首页 > 解决方案 > 为什么我的代码收到 fileNotFoundException 错误?

问题描述

这是代码:

我是java和stackoverflow的新手,所以请原谅任何错误。

public class Actions {
    
    private static String datesFileName = "./Dates.txt";
    
    private static String actionsFileName = "./Actions.txt";
    
    private static File datesFile = new File(datesFileName);
    
    private static File actionsFile =  new File(actionsFileName);
    
    
    private static ArrayList<String[]> actions = new ArrayList<>();
    
    private static ArrayList<Date> dates = new ArrayList<>();
    
    public Actions() throws FileNotFoundException, ParseException {
        
        txtToDates();
        
        txtToActions();
        
    }

    public static void txtToActions() throws FileNotFoundException {
        
        Scanner tempSc = new Scanner(actionsFile);
        
        int counter = 0;
        
        while(tempSc.hasNextLine()) {
            actions.add(new String[24]);
            for(int innerCounter=0; innerCounter<24; innerCounter++) {
                actions.get(counter)[innerCounter] = tempSc.next();
            }
            counter++;
        }
        tempSc.close();
    }

}

当我尝试在另一个类中创建所述类的实例时,我得到一个文件未找到异常。这是为什么?构造函数中的错误在哪里,如何修复?我迷路了,因为我有类似的方法和类似的类,而且运行得很好。

标签: javafilenotfoundexception

解决方案


推荐阅读