我正在尝试让我的Java程序工作,但它给了我这个错误:
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)
所以从第二行开始它就说找不到文件得分.txt,即使我把那个文件放在与类文件(ScoresReader.java)相同的目录中。
我还根据以下说明在Netbeans 8.1 IDE配置框中设置文件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 :(得分:-1)
打开&#34;文件&#34;来自菜单栏的菜单
选择项目属性
转到&#34;运行&#34;标签
在&#34;参数&#34;中插入所需的参数。字段
按&#34;运行&#34;
此信息来自"Netbeans IDE Blog by Tushar Joshi, Nagpur: Using Command Line Arguments in NetBeans IDE"