My web application runs on Windows. I would like to run my app on Linux also. I seem to have overcome most of the problems such as path separator, etc.
Real problem now is I get FileNotFoundException
when the Java code tries to open a file say Abc.txt
when only abc.txt
exists. :(
I can't go on changing all the filenames to lowercase or uppercase as i have a whole lot of files. Without changing code much is that any possible way to avoid this?
How to avoid FileNotFoundException in java? Please ensure file exists when you try to read from file from path exists (using FileInputStream) to avoid FileNotFoundException. Please ensure file exists when we try to acces file from invalid path using RandomAccessFile to avoid FileNotFoundException.
Java is a case-sensitive language, which means that the upper or lower case of letters in your Java programs matter.
FileNotFoundException occurs at runtime so it is a checked exception, we can handle this exception by java code, and we have to take care of the code so that this exception doesn't occur.
Handling FileNotFoundException In order to handle the exception, it is required to use the try-catch block. In the try block, we will put that line of code that can throw an exception. Whenever an exception occurs, the catch block will handle it.
Fix it!
Any scheme you devise to circumvent fixing it will be worse in the long run.
There is no way to avoid this as the java.io.File
API is system-dependent. You have to use the right case when manipulating files on Linux/Unix. Actually, my advice/solution would be to follow strict and portable conventions during development on Windows (e.g. use lower case filenames only or, better, use the exact file name when accessing it programmatically). To be honest, I don't understand why you are trying to load Abc.txt
when the filename is abc.txt
. This is a bad habit (taught by spending too much time on Windows) rather than a Linux/Unix problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With