In Java, what is the default location for newly created files?
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.
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.
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.
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()
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With