Question

I cannot find this simple piece of information in the Javadoc anywhere, or anywhere else for the matter.

Let's say I have a file in the path C:\users\userOne\myFile.exe

And I create a File instance with the above directory

String myFile = "myFile.exe";
File file = new File("C:\users\userOne\" + myFile);

Do both functions below return true?

file.exists("C:\" + myFile);
file.exists("C:\users\userOne\" + myFile);
Was it helpful?

Solution

The answer is both. If it is an absolute path, then it will use absolute path. If the path is relative, then it is relative. I'm not sure what else to tell you?

By the way, your first example won't work because c:\myFile.exe doesn't exist. Also, as pointed out, that method doesn't take parameters.

// current working directory
System.getProperty("user.dir")

OTHER TIPS

I understood the answer, you are looking for : In Java, We have to escaping important while pointing to some path.

\\ is used for escaping the backslash.

Try this, you should be good:

C:\users\userOne\" + myFile

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top