0

This is actually driving me crazy. I do not understand why cannot I read a simple .txt file.

FileInputStream inputStream = new FileInputStream("/Resources/ExternalArchives/tokens.txt");
    try {
        String everything = IOUtils.toString(inputStream);
    } finally {
        inputStream.close();
    }

As you might have guessed, the file is located inside the project, in a Source folder called Resources. I have tried everything possible and keep getting the same exception.

java.io.FileNotFoundException: ExternalArchives\tokens.txt (The system cannot find the path specified)

Other paths that I have tried...

"/Smoothie/Resources/ExternalArchives/tokens.txt"
"/Resources/ExternalArchives/tokens.txt"
"/ExternalArchives/tokens.txt"
"ExternalArchives/tokens.txt"
"tokens.txt"

I am using Eclipse IDE Neon.3.

Thank you!

Raúl
  • 3
  • 2

1 Answers1

1

It should be something like:-

"src/Resources/ExternalArchives/tokens.txt"

The first / in your path means "from the root of the filesystem". Depending where exactly the Resources folder is (I'm assuming in a folder called "src"), then leaving out the slash will make it relative to where the Java app is running from.

Steve Smith
  • 2,244
  • 2
  • 18
  • 22
  • 1
    wow, I feel stupid. The folder was not actually inside the src folder, but removing the initial "/" worked. Thank you very much. – Raúl Apr 05 '17 at 11:33