我有異步任務,必須將文件夾「文件」從資產寫入SD卡上的文件夾。但沒有任何工作。java android複製文件資產
final String sdDir = "/sdcard/izuchaika/";
new Thread(new Runnable() {
public void run() {
try {
InputStream in = getAssets().open("Files");
OutputStream out = new FileOutputStream(new File(sdDir));
try {
byte[] bucket = new byte[32 * 1024];
int bytesRead = 0;
while (bytesRead != -1) {
bytesRead = in.read(bucket);
out.write(bucket, 0, bytesRead);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (in != null)
in.close();
if (out != null)
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
一般提示:*不要*硬編碼到外部存儲/ SD卡*路徑(如你在你的代碼的1號線一樣)*。請改用['Environment.getExternalStorageDirectory()'](http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()),因爲實際路徑和存儲類型因設備而異* (有些內置閃存代替SD卡)* – 2011-11-27 21:49:37