[英]java android copy files assets
我有一个异步任务,该任务必须将资产的文件夹“文件”写入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();
您正在将目录写入和读取为文件。
更换
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"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.