Android的如何使用文件就可以从内部存储器到外部文件夹复制 [英] Android how to copy folder with files on it from Internal memory to External
本文介绍了Android的如何使用文件就可以从内部存储器到外部文件夹复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到一种方法如何在我的设备的内部存储创建特定文件夹中的文件到外部存储设备的特定文件夹。
I need to find a way how to create files from specific folder in Internal Storage of my device to a specific folder in External Storage.
例如:
- 我在
数据/数据/ app_package /文件/文件/服务器/用户名/存储/
内部存储器中。 50的图像文件 - 我想所有的文件复制到该目录为
/ SD卡/文件/服务器/用户名/存储/
- I have 50 image files in
data/data/app_package/files/documents/server/userId/storage/
in Internal Storage. - I want to copy all of the files in that directory to
/sdcard/Documents/Server/UserId/Storage/
和的想法是,在某些情况下,也许我将不得不移动文件,如50MB,也许更多。任何建议,我怎么能做到这一点?
And the idea is that in some cases maybe I'll have to move files like 50MB and maybe more. Any suggestions how can I achieve this?
推荐答案
试试这个code
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);
}
}
这篇关于Android的如何使用文件就可以从内部存储器到外部文件夹复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文