How to create a txt file in a bin folder

I am working on a java project and I was wondering if it is possible to write code that can create a txt file directly in the bin folder (for example, the bin folder for eclipse, where I can use getClass() to access txt files) so that the user does not could see the created txt files when using the program.

+4
source share
1 answer

Can you do this. But think again. The user does not start the program from Eclipse. A user usually starts a program packaged in a jar, so all class files are not in the file system, but in the bank. In addition, the user probably does not even have write permissions to the file system, except for special folders.

On the bottom line: you want to create an application that stores some data at runtime on the file system, you must either use the user's home or temporary directory, or use java.util.prefs.Preferences , which provide a platform-independent way of saving and retrieving data using the file system in unix and the registry in windows.

If you create the file yourself, you can restore the home and temporary directory using the system properties user.home and java.io.tmpdir .

+5
source

Source: https://habr.com/ru/post/1443716/


All Articles