我有异步任务,必须将文件夹“文件”从资产写入SD卡上的文件夹。但没什么用。
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();
答案 0 :(得分:1)
您正在编写和读取目录作为文件。
替换
InputStream in = getAssets().open("Files");
OutputStream out = new FileOutputStream(new File(sdDir));
与
InputStream in = getAssets().open("Files/exit.png");
OutputStream out = new FileOutputStream(new File(sdDir+"/exit.png"));