here is my code:
File file1 = new File("");
System.out.println(file1.exists()); // why the output is false?
System.out.println(file1.getAbsolutePath());
// assume that my current path is "d:/xxx/yyy"
File file2 = new File(".");
System.out.println(file2.getPath()); // i want to get ""
// but i actually get ".",
// which is not i want.
// so how can i get ""
to sum up, what i want is an object file of class File, which when i call
file.getPath() it returns “”
and when i call file.exists() it returns true;
If you really just want to have the current working directory in a string, you can simply use
System.getProperty("user.dir"), see System Properties.Otherwise you’ll have to use
.for the “current working directory” and use File#getCanonicalPath() the get the canonical representation of thisFileobject. Also see File#getCanonicalFile().