tags:

views:

71

answers:

3

In java,

File f;
f = new File("myfile.txt");
if (!f.exists()) 
{
    f.createNewFile();
}

when excute the above code,which path is assigned in default, while specific path is not given?

+2  A: 

The current directory.

CuriousPanda
+2  A: 

The current directory. Apparently System.getProperty("user.dir") can get this for you.

Ignacio Vazquez-Abrams
Just as a somewhat unrelated warning: don't try to set that property, it will behave strangely ;-)
Joachim Sauer
+3  A: 

The current directory, which you can get by calling:

new File('.').getCanonicalPath();
Chinmay Kanchi
getAbsolutePath() may give a friendlier result on unix systems as getCanonicalPath() resolves symlinks... this may give odd results such as converting /home/me to an odd path such as: /mnt/server/dsk/homedirs/m/mydir
CuriousPanda
Fair enough. Though for most/all purposes, it shouldn't matter if you're using the canonical or absolute path.
Chinmay Kanchi