首页 > 代码库 > In Java, what is the default location for newly created files?

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

If the current directory of the application. If e.g. 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.

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