【发布时间】:2015-05-31 17:05:20
【问题描述】:
我正在探索在内部保存而不是保存在 sdcard 上。目前,我正在尝试在 sdcard 上保存一个自定义对象(DummyTwice),如下所示:
String root = (Environment.getExternalStorageDirectory().toString());
File dir = new File(root + PUB_EXT_DIR);
dir.mkdirs();
File file = new File(dir,FILE_NAME);
try {
DummyTwice dt = new DummyTwice(textEnter.getText().toString());
FileOutputStream os = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(dt);
oos.close();
os.close();
Toast.makeText(v.getContext(),"Object Saved",Toast.LENGTH_SHORT).show();
Toast.makeText(v.getContext(),file.getAbsolutePath(), Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
执行停止于:
FileOutputStream os = new FileOutputStream(file);
捕获异常:
FileNotFoundException e
我做错了什么?相关常量:
private final static String PUB_EXT_DIR = /data
private final static String FILE_NAME = /obj.dat
【问题讨论】: