简体   繁体   中英

In Java, what is the default location for newly created files?

在Java中,新创建的文件的默认位置是什么?

If the current directory of the application. If eg you create a File by using

new FileOutputStream("myfile")

then it is created in the "current" directory, which can be retrieved by calling

System.getProperty("user.dir");

However if you change the current directory by calling native methods (very unlikely!), the property is not updated. It can be seen as the initial current directory of the application.

If you start your Java app in a batch file, and doubleclick on the link to it, the current directory will be the directory where the batch file resided, but this can be changed in the link.

If you start your Java app from the command line, you already know the directory you are in.

If you start your Java app from the IDE, the current directory is usually the project root, but this can usually be configured in the launch configuration.

UPDATE 2017-08:

You could also always find the current correct location with new File(".").getAbsolutePath() .

Hoping you are using eclipse or net beans ide.The newly created files will be stored in the project workspace based on how you create the file. Eg you can create a file by 1) using createfilename 2)by using file FileOutputStream,FileWriter,PrintWriter etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM