簡體   English   中英

java.io.FileNotFoundException

[英]java.io.FileNotFoundException

我正在嘗試通過網絡抓取一些數據,以便可以在應用程序中使用它們。

我正在嘗試獲取數據的站點是yahoo,但是在嘗試流式傳輸數據時遇到了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();    

問題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);

我的猜測是文件的路徑不在您認為的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM