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);
Était-ce utile?

La 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")

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top