import java.io.*;
import java.net.*;
public class JavaSourceViewer{
public static void main(String[] args) throws IOException {
String java.io.BufferedReader.readLine() throws IOException
System.out.print("Enter url of local for viewing html source code: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String url = br.readLine();
try {
URL u = new URL(url);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
int code = uc.getResponseCode();
String response = uc.getResponseMessage();
System.out.println("HTTP/1.x " + code + " " + response);
InputStream in = new BufferedInputStream(uc.getInputStream());
Reader r = new InputStreamReader(in);
int c;
FileOutputStream fout=new FileOutputStream("D://web-content.txt");
while ((c = r.read()) != -1) {
System.out.print((char)c);
fout.write(c);
}
fout.close();
} catch (MalformedURLException ex) {
System.err.println(url + " is not a valid URL.");
} catch (IOException ie) {
System.out.println("Input/Output Error: " + ie.getMessage());
}
}
}
我不知道这有什么问题,但是代码不仅显示错误而运行。
它是代码。看起来您遇到了复制/粘贴错误。不允许在其他方法的主体中使用方法声明。从main
方法中删除此分部方法声明
String java.io.BufferedReader.readLine() throws IOException
有时重新启动日食可以解决这个问题。还要确保 jdk 路径准确,并尝试再次配置它,最后使用 eclipse 工具清理项目