Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javac responds with "not a file" but the file exists

When I compile one Java file with javac, it responds with the error not a file (instead of file not found):

enter image description here

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:

enter image description here

After that, I created an empty java file under Onedrive and tried again, which also shows the not a file error:

enter image description here

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.

like image 594
cvifli Avatar asked Jan 20 '18 22:01

cvifli


People also ask

Why is my file not being found in Java?

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.

How do I get rid of FileNotFoundException?

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.

Why am I getting a FileNotFoundException?

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.


1 Answers

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.

like image 98
Daniel Avatar answered Oct 11 '22 14:10

Daniel