我想将文档从一个文件夹复制到另一个文件夹。在新文件夹中,文件名应该是oldFileName + timeStamp。 我已经走了这么远:将文件从一个文件夹复制到另一个文件夹,并使用旧文件名+时间戳重命名新文件夹中的文件
public static void main(String[] args) throws IOException {
File source = new File("C:\\Users\\rr\\test\\XYZ.docx");
File destination=new File("C:\\Users\\rr\\XYZ.docx");
FileUtils.copyFile(source,destination);
// copy from folder 'test' to folder 'rr'
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH-mm-ss");
String ts=sdf.format(source.lastModified());
String outFileName = destination.getName() + ts ;
//appending ts to the file name
System.out.println(" new file name is "+outFileName);
}
我能够将文件从文件夹中测试复制到文件夹RR但文件名保持不变。我怎样才能将这个新的文件名更改为oldFileName + timeStamp?
谢谢!这工作! –