我有一个功能可以将存储在资产中的JPEG复制到SD卡上。它工作,但非常非常缓慢。 averg文件大小约为600k。有没有更好的方式来做到这一点, 代码:有没有一种快速的方法将文件复制到SD卡
void SaveImage(String from, String to) throws IOException {
// opne file from asset
AssetManager assetManager = getAssets();
InputStream inputStream;
try {
inputStream = assetManager.open(from);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
// Open file in sd card
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File file = new File(extStorageDirectory, to);
try {
outStream = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
int c;
while ((c = inputStream.read()) != -1) {
outStream.write(c);
}
outStream.close();
inputStream.close();
return;
}
可能重复:http://stackoverflow.com/questions/4447477/android-how-to -copy-files-in-assets-to-sdcard –