1
我想寫一個簡單的測試方法,從Asset文件夾複製文件到SD卡。當我嘗試打開SD卡上的文件時,它會崩潰。FileOutputStream在嘗試FileOutputStream(externalStorage.getAbsolutePath())時會導致異常;
代碼
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) {
}
}
你加WRITE_EXTERNAL_STORAGE允許您的應用程序? – auselen
Nop,很容易修復!,感謝您的評論 –