Dees
Dees

Reputation: 45

Java IntelliJ No such file exception even with correct JDK in place

I have tried everything i have seen. Made sure the correct JDK was installed, made sure the txt file was in the correct working directory but nothing. I keep getting the no such file exception. And this is not the only project that i am working on that is giving me this problem. I dont know what the problem is: enter image description here

enter image description here

Upvotes: 0

Views: 2008

Answers (1)

Mikhail Antonov
Mikhail Antonov

Reputation: 1367

When run in IDEA the following code shows that your working directory is a project directory, not the src one:

public class Main {
    public static void main(String[] args) {
        System.out.println("CWD: " + System.getProperty("user.dir"));
    }
}

Which means you should do one of the following:

  • refer to your file with an absolute path
  • refer to you file with "src" in relative path (src/cipher.txt)
  • move file one level up so that "cipher.txt" would work (relative to CWD)
  • change your working directory in runtime, which might be not the best idea

PS: JDK has nothing to do with it

Upvotes: 1

Related Questions