我正在使用以下函数将对象写入外部存储。如何从外部存储中删除写入的数据?
使用它之后,我想从外部存储器中删除该对象以释放内存。 任何人都可以指导我该怎么办?
public boolean saveObject(List<DalCategories> obj) {
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"MyCustomObjectForSearchFilter");
} else {
cacheDir= getCacheDir();
if(!cacheDir.exists()) {
cacheDir.mkdirs();
}
final File suspend_f = new File(cacheDir, "test");
FileOutputStream fos = null;
ObjectOutputStream oos = null;
boolean keep = true;
try {
fos = new FileOutputStream(suspend_f);
oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
} catch (Exception e) {
keep = false;
} finally {
try {
if (oos != null) {
oos.close();
}
if (fos != null) {
fos.close();
}
if (keep == false) {
suspend_f.delete();
}
} catch (Exception e) {
keep = false;
}
}
return keep;
}
调用.delete方法后,它会直接从外部存储中删除该文件? – UMAR 2011-01-06 13:49:25