문제

I built a project in eclipse that uses a txt file. the file is located in the main folder project.

I get the file name as argument via command line, and I get FileNotFoundException. I try to use Scanner Object and get the file name as input from eclipse.. and it's worked. (I insert only the file name : file.txt . not the full path) so why via the eclipse it's work and with command line not?

thank you! this is the exception:

  java.io.FileNotFoundException: bigMaze.txt (The system cannot find the file spec
    ified)
            at java.io.FileInputStream.open(Native Method)
            at java.io.FileInputStream.<init>(FileInputStream.java:146)
            at java.io.FileReader.<init>(FileReader.java:72)
            at BFS.BFS.readFile(BFS.java:43)
            at BFS.BFS.InsertMaze(BFS.java:57)
            at BFS.BFS.StartMain(BFS.java:16)
            at search.main(search.java:20)
    Exception in thread "main" java.lang.NullPointerException
            at BFS.BFS.InsertMaze(BFS.java:62)
            at BFS.BFS.StartMain(BFS.java:16)
            at search.main(search.java:20)
도움이 되었습니까?

해결책

If you're running from the command line, try placing the file in the same directory as the .class file

ProjectRoot
       bin
          file.txt
          program.class
       src

If the program is running from eclispe, then the file should go where you originally had it. directly under the project root.

This is all considering your running the program with String filename = "file.txt";

다른 팁

I think the problem is regarding pathname of your txt file. In case of command prompt you have to provide full path like: "MyComputer://D/yourFile.txt" but using eclipse you can give just "D://yourFile.txt". It will work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top