Skip to content
Advertisement

NoSuchFileException java

So I’m currently working on a java fx project and I am trying to get my program to read 2 txt files (name.txt) and (password.txt). When I run this in IntelliJ it works as intended but when I run the jar file in power shell I get this:

JavaScript

the code that is supposed to tell where to look at the text files are this:

JavaScript

Also the .txt files are in the project folder

Advertisement

Answer

From your stacktrace, I see that the file in question is “C:Usersybalddetailsname.txt”. If it’s not found, it’s probably not there, and so I guess you used a relative path. The path is relative to the directory your started the jvm in. Your IDE uses another directory than you do when you start your program unfroh the shell.

Use an absolute path, and it will work. You can use dir.resolve(filename) to turn your relative path into an absolute one.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement