【发布时间】:2011-05-25 19:37:13
【问题描述】:
我正在尝试将文件保存到内部存储器(不是 SD 卡)。正如文档指出的那样,如果我使用getExternalStorageDirectory(),数据将放在/Android/data/<package_name>/ 下,但那里什么都没有。此代码取自here。不过,Archos 上也有类似的代码。
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "DemoPicture.jpg");
txtList.append(file.getPath());
try {
path.mkdirs();
InputStream is = getResources().openRawResource(R.drawable.icon);
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
} catch (IOException e) {
Log.d("ExternalStorage", "Error writing " + file, e);
}
我使用 Android SDK 2.1。权限 WRITE_EXTERNAL_STORAGE 已添加到清单中。 logcat 中没有错误。有什么提示吗?
【问题讨论】:
标签: file data-storage android