小编the*_*928的帖子

适用于浏览器的 URL 的 FileNotFoundException

我正在尝试将https://us.mc-api.net/ 中的 API用于项目,并将其作为测试。

public static void main(String[] args){
     try {
         URL url = new URL("http://us.mc-api.net/v3/uuid/193nonaxishsl/csv/");
          BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
          String line;
          while ((line = in.readLine()) != null) {
                System.out.println(line);
                }
          in.close();  
                 }
                    catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                    catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("I/O Error");

                    }
                }
}
Run Code Online (Sandbox Code Playgroud)

这给了我一个 IOException 错误,但是当我在网络浏览器中打开同一个页面时,我得到

false,Unknown-Username
Run Code Online (Sandbox Code Playgroud)

这是我想从代码中得到的。我是新手,真的不知道为什么会发生这种情况或为什么会这样。编辑:堆栈跟踪

java.io.FileNotFoundException: http://us.mc-api.net/v3/uuid/193nonaxishsl/csv/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at com.theman1928.Test.Main.main(Main.java:13)
Run Code Online (Sandbox Code Playgroud)

java ioexception

3
推荐指数
1
解决办法
5052
查看次数

标签 统计

ioexception ×1

java ×1