這是試圖解析傳入文件時,我遇到了錯誤:嘗試使用緩衝讀取器在java中輸入文件。獲得一個FileNotFoundError
錯誤在解析文件。 java.io.FileNotFoundException:input.txt的是java(系統找不到指定的文件 ) 在java.io.FileInputStream.open0(本機方法) 在java.io.FileInputStream.open(來源不明) 。 io.FileInputStream。(未知來源) 在java.io.FileInputStream中。(未知來源) 在java.io.FileReader。(未知來源) 在MovieDatabaseManager.parseInputFile(MovieDatabaseManager.java:47) 在MovieDatabaseManager。(MovieDatabaseManager的.java:32) 在MovieDatabaseManager.main(MovieDatabaseManager.java:206)
這是代碼:
public MovieDatabaseManager(String file)
{
this();
parseInputFile(file); //populates database with list of movies
}
/**
* Parses the input file so that you can add all of items found in the list
in alphabetical order by title.
*/
private void parseInputFile(String file)
{
//Create a file input stream
Movie m;
String instr;
try
{
//Create input reader
BufferedReader in = new BufferedReader(new FileReader(file));
while (in.ready())
{
instr = in.readLine();
//Try to parse the movie using the appropriate movie
//constructor. If it fails, an exception is caught
try
{
m = new Movie(instr);
////////////////////////////////////////////////////
//Add code to insert m here into your list
////////////////////////////////////////////////////
}
catch (InvalidMovieException e)
{
System.out.println("Invalid movie string " + instr + " in
`enter code here`file " + file);
}
}
}
catch (IOException io)
{
System.err.println("Error in Parsing file.");
io.printStackTrace();
}
}
您的文件路徑可能不正確 – notyou
@pruntlar說了些什麼。你的程序幾乎肯定不在文件的正確位置。 – Scrambo
您需要了解*相對文件名*和當前目錄*是什麼。它們並不特定於Java,而是在您可以有效使用文件之前必須瞭解的一般計算概念。 – VGR