Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application which reads and writes to a file.
File is written to the disk. Its ok, object involved are FileWriter, BufferedWriter . Uptill this is ok. but when reading from the same file is involved , FileNotFound Exception arises. Objects used are FileReader, BufferedReader.
Also the path given is Okay.
but the above error arises
I can't figure it out where's the problem. Needed help in this regard...

What I have tried:

I have scrutenised the coding of the application several times but in vain.
Posted
Updated 24-Dec-22 21:10pm
Comments
CPallini 25-Dec-22 2:54am    
Without seeing your code, the input and the output, how could we possibly help you?

From 'The Documentation': FileNotFoundException (Java Platform SE 6)[^]

This exception will be thrown [..] when a file with the specified pathname does not exist. It will also be thrown [...] if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing.

So either
  • The path you provided is wrong (likely).
or
  • Your code cannot gain access to the file (less likely, but indeed possible).

Without further details, providing better help is difficult.
 
Share this answer
 
To add to what CPallini says, check your code to write the file: if it does not fully close the stream that does the writing, then the file will be in use with an exclusive lock until your application closes and the lock is automatically released.
 
Share this answer
 
Comments
Member 12712527 25-Dec-22 11:20am    
Sir the code is OKAY . when I stored the value(filename) in a string str and compared it with a file having the same value the result was unequaland FileNotFound exception arose. but when i declared...
File fd=new File(path + "\\"+ str) and then compared it with another file having the same value as of str.....i.e. fd.getName.equal(fr.getName)--this file has the same value as of str...the result was equal and it worked
OriginalGriff 25-Dec-22 11:47am    
Did you listen to what Carlo and I said? If the file is in use, your get a "file not found" error when you try to open it.

Check the writing code and make sure the stream is closed ... and never, ever assume "the code is OKAY" when it isn't working ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900