-1
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());
        }
    }
}  

我不知道这有什么问题,但代码没有运行,只是显示错误。

4

2 回答 2

2

代码。看起来您遇到了复制/粘贴错误。不允许在其他方法的主体中声明方法。main从方法中删除此部分方法声明

String java.io.BufferedReader.readLine() throws IOException
于 2013-07-06T08:50:47.690 回答
0

有时重新启动eclipse可以解决它。还要确保jdk路径准确并尝试再次配置它,最后使用eclipse工具清理项目

于 2013-07-06T08:58:05.447 回答