문제

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);
도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top