java - 为什么我的代码收到 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();
}
}
当我尝试在另一个类中创建所述类的实例时,我得到一个文件未找到异常。这是为什么?构造函数中的错误在哪里,如何修复?我迷路了,因为我有类似的方法和类似的类,而且运行得很好。
解决方案
推荐阅读
- java - 使用 Java 中的 if 语句检查 int[] 数组是否在范围内
- css - 如何使一个网格列按比例大于另一列?
- java - 使用值对枚举列表进行排序的快速方法
- kubernetes - 如何在 kubernetes 中使用自定义镜像 pull secret 创建 dask-gateway 工作节点
- javascript - 我的代码不起作用:有人可以帮助我吗?
- c# - 如果在代码中使用了 Response.Write,则 asp 按钮不起作用
- javascript - 等待导入的 puppeteer 函数完成然后开始新的一行 nodeJS
- mysql - 如何在一个 sql 语句中编写 max、group by、where、order by?
- r - contingencyTableBF 是否有循环
- c# - 关于在 ASP.net core mvc 中创建区域的错误