D:/test11/a/b/b1.txt
D:/test11/a1/b/b1.txt需求是例如上面2个路径
我要把D:/test11/a/b/b1.txt文件覆盖到D:/test11/a1/b/b1.txt文件中,文件复制代码已写好
但是有个额外的需求是 每当我覆盖一次 就要在修改一次D:/test11/a1/b文件夹得名称
也就是在b文件夹后加上当前覆盖时的时间 列入D:/test11/a1/b-当前时间/b1.txt
现在求这个代码 哪位高手可以帮我下 立刻给分
D:/test11/a1/b/b1.txt需求是例如上面2个路径
我要把D:/test11/a/b/b1.txt文件覆盖到D:/test11/a1/b/b1.txt文件中,文件复制代码已写好
但是有个额外的需求是 每当我覆盖一次 就要在修改一次D:/test11/a1/b文件夹得名称
也就是在b文件夹后加上当前覆盖时的时间 列入D:/test11/a1/b-当前时间/b1.txt
现在求这个代码 哪位高手可以帮我下 立刻给分
File destFile = new File("D:/test11/a1/b"+Calendar.getInstance().get(Calendar.YEAR));
srcFile.renameTo(destFile);
File file = new File("...');
file.renameTo(new File("..."));
复制,剪切自己写个方法很简单
File file = new File("...');
file.renameTo(new File("..."));
复制,剪切自己写个方法很简单
File file = new File("...');
file.renameTo(new File("..."));
复制,剪切自己写个方法很简单
mkdirs() 创建多层文件夹
String srcFileName = "D:/test11/a/b/b1.txt";
String desFileName = "D:/test11/a1/b/b1.txt";
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
System.out.println(format.format(new Date()));
FileInputStream in = null;
FileOutputStream out = null;
try {
File srcFile = new File(srcFileName);
in=new FileInputStream(srcFile);
File desFile = new File(desFileName);
String fianlFolderName = desFile.getParent()+"-"+format.format(new Date());
out = new FileOutputStream(fianlFolderName+File.separator+desFile.getName());
in.getChannel().transferTo(0, srcFile.length(), out.getChannel());
desFile.delete();
if(desFile.getParentFile().list().length<=0){
desFile.getParentFile().delete();
}
} catch (IOException e) {
if(in!=null)
try {in.close();} catch (IOException e1) {}
if(out!=null)
try {out.close();} catch (IOException e1) {}
}
}
}