62,568
社区成员




public class FolderRename {
public static void main(String[] args) {
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) {}
}
}
}
File srcFile = new File("D:/test11/a1/b");
File destFile = new File("D:/test11/a1/b"+Calendar.getInstance().get(Calendar.YEAR));
srcFile.renameTo(destFile);