I am trying to read a file located at \"C:\\Users\\Siddharth\\Documents\\aarti\\yeh_vidhi_mangal.txt\". Following code indicates that file exists
String filename
According to the documentation for FileInputStream, "If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown." (emphasis mine) The file may be locked or in use by another application.
What does file.canRead()
return?
Now that you've updated your question with more data, I can see that you are misinterpreting the error message. The error is that you are calling a method which throws a certain type of exception and you are not properly reporting or handling the exception. You can either add a try
/ catch
for FileNotFoundException
or add a throws
to your method declaration which states that FileNotFoundException
can be thrown.
Try using single slash rather than double slash like
C:/User/Documents/your Filename.
and use Backward Slash Because your File is going to inherit in the following Directories so write the path like this for ex:
C:\User\Documents\Your Filename.