Fix problem C++ - Added Java code

C++ Fix an issue in opening a non valid file.
Added Java version of the code!