gpt4 book ai didi

java - 为什么即使 url 工作正常,此代码也会抛出 java.io.FileNotFoundException

转载 作者:行者123 更新时间:2023-12-01 17:16:49 25 4
gpt4 key购买 nike

我在这个特定网站 (nandos.co.uk/southharrow) 上收到此错误。其他网址工作正常。有谁知道为什么吗?

java.io.FileNotFoundException: http://www.nandos.co.uk/southharrow at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

public class Test {
public static void main(String[] args) {
HttpURLConnection conn = null;
StringBuilder result = new StringBuilder();
try {
String website = "http://www.nandos.co.uk/southharrow";
URL url = new URL(website.trim());
conn = (HttpURLConnection) url.openConnection();
InputStreamReader in = new InputStreamReader(conn.getInputStream());

int read;
char[] buff = new char[1024];
while ((read = in.read(buff)) != -1) {
result.append(buff, 0, read);
}
} catch (MalformedURLException e) {
System.out.println("Error processing Places API URL");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Error connecting to Places API");
e.printStackTrace();

} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}

}
System.out.println(result.toString());
}

}

最佳答案

$ wget http://www.nandos.co.uk/southharrow
--2014-01-29 16:28:31-- http://www.nandos.co.uk/southharrow
Resolving www.nandos.co.uk... 162.13.100.232
Connecting to www.nandos.co.uk|162.13.100.232|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2014-01-29 16:28:31 ERROR 404: Not Found.

该地址不存在 URL。您看到的页面是出现错误时显示的默认页面。类似于“FileNotFoundException”

关于java - 为什么即使 url 工作正常,此代码也会抛出 java.io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21442977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com