Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 761
abhishek kumar gupta Avatar asked Mar 01 '11 12:03

abhishek kumar gupta


People also ask

What is default path Java?

The Java Runtime Environment file javaw.exe (which is the non-windowed version of java.exe ) is located at: C:\Program Files\Java\jre[version]\bin\javaw.exe.

Where does Java file look for files?

Eclipse looks for the file exactly in the root folder of the project (project name folder). So you can have src/test.in to locate file inside src folder of the project.

Does Java file Create a new file?

File class can be used to create a new File in Java. When we initialize File object, we provide the file name and then we can call createNewFile() method to create new file in Java. File createNewFile() method returns true if new file is created and false if file already exists. This method also throws java.


2 Answers

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.

UPDATE 2017-08:

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

like image 137
Daniel Avatar answered Sep 19 '22 23:09

Daniel


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.

like image 32
Pradeep Avatar answered Sep 21 '22 23:09

Pradeep