我正在使用 Android Studio。是否有可能的命令会复制 DCIM 文件夹中的图片并将其移动到 SD 卡的根目录?我已经研究过,但一无所获。我已经反编译了其他应用程序,但一无所获。您可能会说我是普通程序员的初学者。我刚开始为这个项目使用 Java。
即使没有我也想知道所以我可以停止在网上搜索答案:P
谢谢,欢迎所有评论,如果需要会发布更多信息! :)
最佳答案
使用这个函数
public void copyFile(File sourceFile, File destFile)
throws IOException {
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
FileInputStream is = null;
FileOutputStream os = null;
try {
is = new FileInputStream(sourceFile);
os = new FileOutputStream(destFile);
source = is.getChannel();
destination = os.getChannel();
long count = 0;
long size = source.size();
while ((count += destination.transferFrom(source, count, size
- count)) < size)
;
} catch (Exception ex) {
} finally {
if (source != null) {
source.close();
}
if (is != null) {
is.close();
}
if (destination != null) {
destination.close();
}
if (os != null) {
os.close();
}
}
}
关于java - Java复制文件的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31848454/