2016-02-14 57 views
0

我試圖讓我的Java程序的工作,但它給了我這個錯誤:使用命令行參數在NetBeans IDE的8.1 ​​

run: 
Can't find file scores.txt 
java.io.FileNotFoundException: scores.txt (The system cannot find the file specified) 
at java.io.FileInputStream.open0(Native Method) 
usage: java ScoresReader sourceFile destFile 
at java.io.FileInputStream.open(FileInputStream.java:195) 
at java.io.FileInputStream.<init>(FileInputStream.java:138) 
at java.util.Scanner.<init>(Scanner.java:611) 
at Scores.project.ScoresReader.readData(ScoresReader.java:65) 
at Scores.scoresreader.ScoresReader.main(ScoresReader.java:260) 
java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: 
    cern.list.IntArrayList 
at Scores.scoreseader.ScoresReader.main(ScoresReader.java:262) 
BUILD SUCCESSFUL (total time: 2 seconds) 
從2號線它說,它無法找到該文件的分數

左右。即使我將該文件放在與類文件(ScoresReader.java)相同的目錄中。

我還設置在NetBeans IDE 8.1配置中的文件scores.txt和dest.txt根據給出的說明如下:

1. Right click the project name and choose Set Configuration | Customize ... 
2. In the configuration dialog, I typed the two files: scores.txt dest.txt 
in the arguments box. And the two files showed up in the IDE o.k. Nothing 
seem to be wrong there. 

當我跑的項目或文件,它給我的以上錯誤。這是一個縮寫代碼片段:

public class ScoresReader implements Serializable 
    { 
    private static final long serialVersionUID = 7526472295622776147L; 
    public OpenIntIntHashMap Scores; 

    /** 
    * Default constructor. Initializes hashtables. 
    */ 
    public ScoresReader() 
     { 
     Scores = new OpenIntIntHashMap(); 
     .. 
     .. 
     } 
    /** 
    * Reads a text file 
    */ 
    public void readData(String fileName) 
     { 
     //Reads from an input text file in the form of: 
     //score_id, user_id, score 
     //and stores this data in the hashtables. 
     } 

    /** 
    * Serializes a ScoresReader object so that it can be read back later. 
    */ 
    public static void serialize(String fileName, ScoresReader obj) 
     { 
     //serialize the score objects 
     .. 
     } 

    public static void main(String args[]) 
     { 
     ScoresReader reader = new ScoresReader(); 
     String sourceFile = null; 
     String destFile = null; 
     try 
      { 
      sourceFile = args[0]; 
      destFile = args[1]; 
      reader.readData(sourceFile); 
      reader.sortScores(); 
      serialize(destFile, reader); 
      .. 
      .. 
      } 
     catch(Exception e) 
      { 
      System.out.println("usage: java ScoresReader sourceFile destFile"); 
      e.printStackTrace(); 
      } 
     }//end main 
    }//end class ScoresReader 

任何人都可以告訴我爲什麼找不到該文件?

在此先感謝!

+0

在NetBeans中,您使用的是默認的包,用於存儲類文件。在這種情況下,將stores.txt存儲在同一個文件中很好。如果你的類文件在'src'文件夾中,那麼txt文件應該是上面的一個文件夾,即../src – ronakshah725

+0

感謝您的建議。是的,我正在使用默認包和我的類文件,其中包括其他所有的輔助文件都在默認包中。什麼意思txt文件應該是上面的一個文件夾?我在IDE中查看,在src文件夾上方是項目文件夾 - 是你的意思嗎?把txt文件放在項目文件夾中?謝謝! – Tuonvarman

+0

O.K--將txt文件放在src文件夾上的一個文件夾似乎擺脫了「無法找到文件」的錯誤。但它給了我一個不同的錯誤,它是:(見下文) – Tuonvarman

回答