Sign in to follow this  

Java in Vista: Reading from a file

This topic is 3309 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
I don't know enough Java to be certain, but my guess is that that code is opening the file for both read and write access, and Vista is picky about where you can write files (but lets you read almost anything).

The same problem will probably happen if you run it as a limited user under XP.

To see exactly what's going on with the low level file system calls SysInternals Process Monitor is very useful.

Share this post


Link to post
Share on other sites
Quote:
Original post by javaFan

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”.


Are you sure that problem is even coming from your application, and it's not Vista saying that it can't find javaw.exe to even start your application?

Also, it's beneficial to post actual source code (example posted here doesn't compile, While/Catch/Try are not capitalized) and actual error message.

Share this post


Link to post
Share on other sites

This topic is 3309 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this