我的一个类找不到我正在通过Java传递的文件

时间:2016-09-25 00:29:12

标签: java javafx

我正在尝试使用其中一个类扫描文件,但找不到该文件。字符串文件名包含文件路径。如果有人能提供帮助那就太棒了,谢谢!

    check.setOnAction(new EventHandler<ActionEvent>(){
        public void handle(ActionEvent event){
            FileChooser fc = new FileChooser();
            File file = fc.showOpenDialog(null);
            if(file != null){
                String filename = FileUtils.readFileToString(file);
                SpellChecker sc = new SpellChecker(filename);
                sc.checker();
                //System.out.println(filename);
            }

        }
    });


public SpellChecker(String filename) 
{

    try (Scanner in = new Scanner(new File(filename));)//go and read the file with the undivided dictionary
    {
        String word="";
        while(in.hasNextLine())//loop through every line
        {
            word=in.nextLine()+" ";// add the words from that line
        }
        wtc = fileSplitter(word);
    } 
    catch (FileNotFoundException ex) // if the file is not found where it is specified to be throw exception.
    {
        System.out.println(E_NOT_FOUND);
        System.exit(0);
    }
}

0 个答案:

没有答案