When I compile one Java file with javac, it responds with the error not a file
(instead of file not found
):
So I tried to compile it in the WSL environment and it compiles the same file fine. Then, I realized that it may be because I put the file under OneDrive, so I moved it out of OneDrive and tried it again, and then javac
worked:
After that, I created an empty java file under Onedrive and tried again, which also shows the not a file
error:
Then, I started to realize that when I "dir" in PowerShell, the mode of files under OneDrive include one "l" symbol, which represents "reparse point". Although I do not really understand what it means, I am curious whether it is because of the l
that I can not compile the java file. Or if is there any other potential problems.
This typically happens because the application's current directory is not what you are expecting or assuming. The path to the file is is broken; e.g. a directory name of the path is incorrect, a symbolic link on the path is broken, or there is a permission problem with one of the path components.
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.
This exception is thrown during a failed attempt to open the file denoted by a specified pathname. Also, this exception can be thrown when an application tries to open a file for writing, but the file is read-only, or the permissions of the file do not allow the file to be read by any application.
In the first image you posted you can see this:
> dir
Mode Name
-a---l helloworld.java
So, what that l
at the end of the mode means is that helloworld.java
is not a file, it's a symlink. And that's what javac
is telling you.
The example you posted in the second image works because that one is actually a file (see the Mode column says -a----
).
The problem is caused by OneDrive, it seems what we see as files are not actually the files but links that point to those files. To avoid the problem, don't place your java files inside the OneDrive folder.
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