这是我在尝试解析传入文件时遇到的错误:
解析文件时出错。java.io.FileNotFoundException: java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.( Unknown Source) at java.io.FileInputStream.(Unknown Source) at java.io.FileReader.(Unknown Source) at MovieDatabaseManager.parseInputFile(MovieDatabaseManager.java:47) at MovieDatabaseManager.(MovieDatabaseManager.java:32) at MovieDatabaseManager.main (电影数据库管理器.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();
}
}