Question

How would you correctly place a folder with files (.txt) in an Eclipse project? These files are being read from / written to during program execution.

Should it look like (where the folder is INSIDE the src folder):

ProjectName
  src
    packagename
       class.java
       class2.java
    FOLDER_CONTAINING_TEXT_FILES

Or more like (where the folder is OUTSIDE the src folder):

ProjectName
  src
    packagename
       class.java
       class2.java
  FOLDER_CONTAINING_TEXT_FILES
Was it helpful?

Solution

Any files you expect to write to should be placed completely outside the project or application. Make your application take a parameter or a setting or look for an environment variable to indicate where this folder is located.

For files that are only read (static resources), you can places them within src folder and read them using ClassLoader.getResourceAsStream() API (as opposed to Java File I/O, which will not work once the application is packaged in a jar).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top