网址是可访问的,但为什么我得到java.io.FileNotFoundException

时间:2011-11-26 17:32:05

标签: java io

  

可能重复:
  FileNotFoundException with URLConnection

这是我的以下计划。

可以访问URL,但为什么我会收到java.io.FileNotFoundException?

    public class TestGet {
    private static URL source; 
    public static void main(String[] args) {
        doGet();
    }
    public static void doGet() {
            try {
            source = new URL("http://localhost:8080/");
            URLConnection connection = source.openConnection();
            connection.connect();

            BufferedReader rdr =new BufferedReader(new InputStreamReader(connection.getInputStream()));
            StringBuffer b = new StringBuffer();
            String line = null;
            while (true) {
                line = rdr.readLine();
                if (line == null)
                      break;
                b.append(line);
          }

        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

}

java.io.FileNotFoundException:http://localhost:8080/

0 个答案:

没有答案