Is it possible to get the error code returned by the operating system from the JVM when calling FileNotFoundException?

Is it possible to get the error code returned by the operating system in the JVM when calling FileNotFoundException?

The problem is that when trying to open a stream of input files to a file when the file is locked by the operating system, a FileNotFoundException is thrown even if the file does exist.

If I try to open a file using code written in C, the operating system returns ERROR_SHARING_VIOLATION as defined in winerror.h. However, the JAVA FileNotFoundException throws an error message "The process cannot access the file because it is being used by another process."

What I would like to do is add some logic to the try / catch to retry opening the file if certain specific errors are encountered, but I cannot figure out how to expand into the FileNotFoundException and find the root cause of the error. The only other option I have is to check the description of the error message, but it just doesn't work for that.

+3


source to share


1 answer


Unfortunately no.

FileNotFoundException

has no subclasses that refine it, and the class itself has no specific accessor methods. This is a common problem and presumably due to the fact that the standard API is designed to be platform independent.



The workaround is usually to parse the string returned getMessage()

, or go to your own level and resolve it platform-specific, for example for C.

+2


source







All Articles