Where do I put the txt file that I want to read in Java?

If you don't want to specify a path, and want to open a File from the file system using the java.io.File API, then put it in the working directory.

In Eclipse, the working directory defaults to the root level of your project, but you can modify it (and also review what it is set to) in an Eclipse Run Configuration. They are accessible under the "Run > Run Configurations..." menu option, and the working directory setting is under the "Arguments" tab for Java programs.


Right click the project folder and click New -> file. The file will be in the Project folder and not in the source folder.


The way this can be done is using .getResourceAsStream("file.txt")

SO thread

Downvoted for a correct answer? Wierd...


Put the file in the folder from where you run your Java application (your current/working folder). If you're using the default settings of Eclipse to run your application, you should put the file directly inside the Eclipse project folder. To create the file in the Eclipse project, you can simply drag-and-drop it there or right-click on the Eclipse project and create a new file.

Tags:

Java

Eclipse

Io