I am trying to web scrape some data so that I can use it in my application.
The site I am trying to get data off is yahoo but I am getting a FileNotFoundException when it's trying to stream the data in.
I have also set the IP address and port explicitly.
Would be really thankful if someone can tell me where I am going wrong.
I have posted the sample code as well.
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();
The problem is in the initialization of out
. You haven't shown us that code, but it will be something like:
OutputStream out = new FileOutputStream("non/existent/path/somefilename");
It's probably due to you using a relative path, so to help you debug it, I recommend you change it to:
File file = new File("non/existent/path/somefilename");
System.out.println(file.getAbsolutePath()); // start with this simple debugging
OutputStream out = new FileOutputStream(file);
My guess is that the path of the file is not where you think it is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.