这是你想做的吗?
FileInputStream fis;
try {
fis = openFileInput("CalEvents");
ObjectInputStream ois = new ObjectInputStream(fis);
ArrayList<Object> returnlist = (ArrayList<Object>) ois.readObject();
ois.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
编辑:可以简化:
FileInputStream fis;
try {
fis = openFileInput("CalEvents");
ObjectInputStream ois = new ObjectInputStream(fis);
ArrayList<Object> returnlist = (ArrayList<Object>) ois.readObject();
ois.close();
} catch (Exception e) {
e.printStackTrace();
}
假设您在一个扩展的类中Context
(如Activity
)。如果没有,那么您将不得不在openFileInput()
扩展的对象上调用该方法Context
。