我需要找到一种方法,如何将设备的内部存储中的特定文件夹中的文件创建到外部存储中的特定文件夹。
示例:
data/data/app_package/files/documents/server/userId/storage/
中有50个图像文件。/sdcard/Documents/Server/UserId/Storage/
这个想法是,在某些情况下,我可能需要移动50MB甚至更多的文件。有什么建议我能做到吗?
答案 0 :(得分:2)
试试这段代码
private void copyToFolder(String path) throws IOException {
File selectedImage = new File(path);
if (selectedImage.exists()) {
String wall = selectedImage.getName();
in = getContentResolver().openInputStream(selectedImageUri);
out = new FileOutputStream("/sdcard/wallpapers/" + wall);
copyFile( in , out); in .close(); in = null;
out.flush();
out.close();
out = null;
} else {
System.out.println("Does not exist");
}
}
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);
}
}