0
喜的朋友,我用這個代碼複製我的資產文件夾到SD卡,但它顯示權限被拒絕,但我考慮到外部存儲許可複製資產的文件夾複製到SD卡中顯示了在安卓
副本資產
private void CopyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
out = new FileOutputStream("/sdcard/" +"Good");
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) {
Log.e("tag", e.getMessage());
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
拒絕的權限
logcat的它顯示權限被拒絕
02-16 21:25:14.227: E/tag(405): /sdcard/Good (Permission denied)
02-16 21:25:14.236: E/tag(405): images
02-16 21:25:14.236: E/tag(405): sounds
02-16 21:25:14.236: E/tag(405): webkit
這是我的清單文件許可標籤
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
'/ sdcard'可能不存在。 **從不硬碼路徑**。在'Environment'或'getExternalFilesDir()'或'getExternalCacheDir()'上使用方法來查找在外部存儲上使用的位置。 – CommonsWare