-2

这是我在尝试解析传入文件时遇到的错误:

解析文件时出错。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();   
    }
    }
4

1 回答 1

-1

您需要使用资源的完整限定路径名来获取它。

例如:C:/dur/dir/file.txt

否则,相对路径可用于执行的 jar 文件的同一层次结构中的文件。

于 2017-09-29T14:38:30.860 回答