Sign in to follow this  

Java in Vista: Reading from a file

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Help people, I am trying to program a java game but because I have vista installed an error is occurring which doesn’t occur when I run the program in linux or XP. All I am trying to do is read from a file. I mean there is nothing wrong with the code except when I run it in a system that run vista it can’t find the file in question. The error thrown is: “the system cannot find the file specified”. Java Code: ---------- String filename=”document.txt”; URL fileURL = getClass().getResource(document); Try { BufferedReader breader = new BufferedReader(new InputStreamReader(fileURL.openStream())); While(nextChar != -1) //not EOF { …. Then I read from the file } Breader.close(); } Catch(IOException e) { System.out.println(“Error: ”+e.getMessage()); } Whatever the suggestion, thanks to anyone who takes the time to respond.

Share this post


Link to post
Share on other sites
If I can find the time, I'll test this at home tonight.
But if it's a text file, wouldn't readline() be a better way to do it?
This method returns null if there are no more lines. Much easier (and faster) then per character reading.

Share this post


Link to post
Share on other sites
I hope those fancy quotation marks aren't actually in your code, because they should fail to compile horribly.

Does the file actually exist on the new system? Is it in the place where you expect it to be? Does the user running the program have permissions to access it?

Share this post


Link to post
Share on other sites

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this