我正在尝试编写一个简单的测试方法,将文件从Asset文件夹复制到SD卡。当我尝试在SD卡上打开文件时,它会崩溃。
码
try {
// POpne file from asset
AssetManager assetManager = getAssets();
InputStream inputStream;
inputStream = assetManager.open("test");
// open output folder
File externalStorage = Environment.getExternalStorageDirectory();
// CRASHES HERE
out = new FileOutputStream( externalStorage.getAbsolutePath() );
int c;
while ((c = inputStream.read()) != -1) {
out.write(c);
}
} catch( Exception e) {
}
}
答案 0 :(得分:1)
您似乎忘记在AndroidManifest.xml中提及文件访问权限,只需在AndroidManifest.xml中写下以下权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>