rusakovic
rusakovic

Reputation: 156

How to open a file in my src directory using just the filename in INTELLIJ

I want to open the file

IntelliJ IDEA Community Edition 14.0.3\examples\assigment_4\src\file.txt

using the following code:

BufferedReader hangmanWordsFromFile = new BufferedReader(new FileReader("file.txt"));

But it throws the exeption

java.io.FileNotFoundException: HangmanLexicon.txt (The system cannot find the file specified)

When I copy file.txt to

IntelliJ IDEA Community Edition 14.0.3\jre\jre\bin

it works.

Printing System.getProperty("user.dir") yields IntelliJ IDEA Community Edition 14.0.3\jre\jre\bin.

How can I change user.dir path so that I can use file.txt as file name to open the file located at IntelliJ IDEA Community Edition 14.0.3\examples\assigment_4\src\?

Upvotes: 0

Views: 771

Answers (1)

Darek Kay
Darek Kay

Reputation: 16649

You should configure your working directory:

Go to Run > Edit configurations, select your run configuration and select your working directory (the one, where your file.txt is in).

Upvotes: 1

Related Questions