[英]How to Copy Image File from Gallery to another folder programmatically in Android
[英]How to Copy Image File from Gallery to another folder without changing its modified date programmatically?
private void copyFile(File sourceFile, File destFile){
try (FileOutputStream fos = new FileOutputStream(destFile)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Files.copy(sourceFile.toPath(), fos);
}
} catch (FileNotFoundException e) {
Log.d("Tag",e.getMessage());
} catch (Exception e) {
Log.d("Tag", e.getMessage());
}
}
我试过上面的代码复制粘贴工作,但修改日期也改变了,我不想改变修改日期。
Date date = new Date(files.get(i).lastModified());
new File(outputPath + "/" + inputFile).setLastModified(newDate.getTime());
在复制之前先获取上次修改日期,然后粘贴后将上次修改日期应用到新文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.