我正在尝试阅读名为Inspirational_Quotes
的文件。 .txt
文件位于我的eclipse 工作区/项目中(目录很好)。我不确定为什么它无法读取/定位文件:
import java.io.*;
import java.util.Scanner;
public class TesterFinal {
private int[] myData = new int[1000];
public TesterFinal(String Inspirational_Quotes)
{
loadFile("Inspirational_Quotes");
}
public void loadFile(String Inspirational_Quotes)
{
int index = 0;
File file = new File(Inspirational_Quotes);
try{
Scanner inFile = new Scanner(file);
while (inFile.hasNext())
{
myData[index] = inFile.nextInt();
index++;
}
}
catch(FileNotFoundException e) {
System.out.println("File Not Found in Directory.");
}
}
public static void main(String[] args)
{
TesterFinal one = new TesterFinal("Inspirational_Quotes");
//one.loadFile("Inspirational_Quotes");
}
}