【发布时间】:2015-02-17 14:28:57
【问题描述】:
我不是第一次在java中使用文件,但这是我第一次使用FileInputStream。
我在 resources/backup.txt 中有一个 TXT
然后在我的代码中,当我将文件放入 FileInputStream 构造函数时,它会抛出 FileNotFoundException。
这是代码:
public void loadList() {
try {
ArrayList<Partido> myList = Pronosticos.getInstance().getMyList();
myList.clear();
File file = new File("resources/backup.txt");
// create an ObjectInputStream for the file
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
// read and print an object and cast it as ArrayList<Partido>
if (file.length() != 0){
myList .addAll((ArrayList<Partido>) ois.readObject());
ois.close();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
我不应该从我的 PC 中放置路径,因为我需要它在另一台 PC 上工作。
【问题讨论】:
-
尝试使用
backup.txt作为文件名而不是resources/backup.txt -
你能提供堆栈跟踪吗..
标签: java filenotfoundexception fileinputstream