我正在尝试web抓取一些数据,以便在我的应用程序中使用它们。
我试图从雅虎获取数据的网站是雅虎,但当它试图流式传输数据时,我得到了一个FileNotFoundException。
我还显式设置了IP地址和端口。
如果有人能告诉我哪里错了,我会非常感激的。
我也发布了示例代码。
parentUrl = "http://www.yahoo.com";
pageUrl = new URL(parentUrl);
System.out.println(parentUrl);
try {
in = new BufferedReader(new InputStreamReader(pageUrl.openStream()));
} catch(Exception ex2) {
ex2.printStackTrace();
}
while ((inputLine = in.readLine()) != null) {
out.write(inputLine);
in.close();
}
out.close(); 发布于 2012-01-31 14:51:25
问题出在out的初始化过程中。您还没有向我们展示该代码,但它将类似于:
OutputStream out = new FileOutputStream("non/existent/path/somefilename");这可能是因为您使用了相对路径,所以为了帮助您调试它,我建议您将其更改为:
File file = new File("non/existent/path/somefilename");
System.out.println(file.getAbsolutePath()); // start with this simple debugging
OutputStream out = new FileOutputStream(file);我的猜测是该文件的路径不是您所认为的位置。
https://stackoverflow.com/questions/9075123
复制相似问题