Крум Илиев
Крум Илиев

Reputation: 117

Where is java saving files on Linux?

so I have this problem:

I need to know where is Java saving the files when you create them with new, like this File file = new File ("file.txt"); on Linux?

Upvotes: 0

Views: 1984

Answers (4)

Memento Mori
Memento Mori

Reputation: 3402

Assuming the file is actually being created by additional code (as Evgeniy mentioned), you could try checking to see if your current working directory isn't what you expect it to be. To find that directory you could try:

String cwd = System.getProperty("user.dir"));
System.out.println("Current working directory: " + cwd);

or just

System.out.println ("Path to file: " + file.getAbsolutePath());

To see where it should end up.

Upvotes: 1

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136002

Linux on not File file = new File ("file.txt") does not create a file on the file system. File is just a file path holder. You need to call file.createNewFile to create a file. Relative paths like file.txt are resolved against the current user directory, typically the directory in which the Java virtual machine was invoked

Upvotes: 1

IConfused
IConfused

Reputation: 724

Your mentioned code doesn't create new file physically on drive, but logically yes. If you alter the code to create a new file like file.createNewFile then the directory where you executed the code, a file would be created there.

Upvotes: 0

morgano
morgano

Reputation: 17422

same place like in Windows: in the current directory

Upvotes: 0

Related Questions