java.io.FileNotFoundException :(系统找不到指定的文件)

时间:2014-04-08 12:26:04

标签: java file

我有一个工作代码,用于从此处发布的文件中返回字符串 java file reading file returning null

现在我有另一个问题需要解决。以下是代码和我的问题

public String findFile()
    {
        String bookId = "";
        blist = lRef.getBookArrayList();
        for (int i = 0; i < blist.size(); i++) {
            bookId =(blist.get(i).getIsbn());}
        String filenameToRead = bookId + ".txt";
        String path = "files";
    //  File folder = new File(path);       //im not using those yet as they wouldnt work   
    //  File infile = new File(path,filenameToRead);

        String line = "";
        try {
                File myFile = new File("files", "ISBN 123-654.txt");
                System.out.println(myFile);
               BufferedReader br = new BufferedReader(new FileReader(myFile));
            while ((line = br.readLine()) == null) {          
                 br.close();}
             } 
             catch (IOException e) {
                 e.printStackTrace();
             }
    return line;
    }

我从arraylist获取一个名字,我在这里用来建立一个文件名

String filenameToRead = bookId + ".txt";

如果我把它打印出来 - 它看起来像这样#34; ISBN 123-654.txt&#34; (并且它正确) 如果我在这里使用filenameToRead而不是文件的硬编码名称

File myFile = new File("files", filenameToRead );
它给了我一个FileNotFoundException。     有什么想法吗?

0 个答案:

没有答案