英文:
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());
}
}
Note: The code part has been translated, and I've removed the request not to provide additional content or answer translation-related questions.
英文:
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());
}
}
I tried above code copy paste working but modified date is also changed and I don't want to change modified date.
答案1
得分: 1
Date date = new Date(files.get(i).lastModified());
new File(outputPath + "/" + inputFile).setLastModified(newDate.getTime());
首先获取复制前的最后修改日期,然后在粘贴后将该最后修改日期应用于新文件。
英文:
Date date = new Date(files.get(i).lastModified());
new File(outputPath + "/" + inputFile).setLastModified(newDate.getTime());
first get last modified date before copy and after paste apply that last modified date to new file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论