Skip to content
Advertisement

How to create txt file in source package folder sub folder ( source package -> invoice)

enter image description here

enter image description here

I need to create a .txt file in the invoices folder. I am using Windows 10. How can I do that? I’ve tried:

File myObj = new File("\invoice\filename.txt");

and

File myObj = new File("/invoice/filename.txt");

But it did not work. Thank you for your support.

Advertisement

Answer

As Jens said do not use a project source folder to write the file. At run-time of the standalone application there might not be a folder invoice, and also you might risk compiling a garbage file into the application jar.

The user’s home directory is System.getProperty("user.home") and work from there on. That is the appropriate directory tree for user specific files.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement