eclipse juno显示错误编辑器不包含主文件,我认为编辑器有一些错误而不是代码

时间:2013-07-06 08:45:30

标签: java eclipse

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

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

2 个答案:

答案 0 :(得分:2)

代码。看起来您有复制/粘贴错误。其他方法的主体内不允许使用方法声明。从main方法

中删除此部分方法声明
String java.io.BufferedReader.readLine() throws IOException

答案 1 :(得分:0)

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

相关问题