我只是想将 URL 加载到 InputStream 中,但它似乎永远无法管理。
private void getWebpage(String url)
{
URL myFileUrl = null;
try
{
myFileUrl= new URL(url);
}
catch (MalformedURLException e)
{
System.out.println("Malformed URL Exception");
}
catch (Exception e)
{
System.out.println("Some URL Exception");
}
try
{
InputStream in = myFileUrl.openStream();
System.out.println("Does it get here?");
is = new BufferedInputStream(in);
in.close();
is.close();
}
catch (IOException e)
{
System.out.println("Some IO Exception");
}
catch (Exception e)
{
System.out.println("Some Exception");
}
}
它永远不会打印出“Does it get here?”到控制台,但它确实打印出一些 IO 异常。我所知道的世界上没有最好的错误消息。
最佳答案
它是否会突破其中一个异常(exception)?如果它无法打开文件,那么它会跳转到 catch 语句
编辑:您实际上是在尝试加载网页吗?
关于java - InputStream 不会打开到指定 URL 的流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8142444/