Here is part of my files:
网址:yii666.com[北京圣思园Java培训教学视频]Java.SE.前9日学习成果测试题(2010年12月2日).rar
[北京圣思园Java培训教学视频]Java.SE.第一百一十一讲.基于UDP的网络通信详解.rar
[北京圣思园Java培训教学视频]Java.SE.第一百一十七讲.Java.SE项目迭代二深度详解之线程对象设计.rar
[北京圣思园Java培训教学视频]Java.SE.第一百一十三讲.Java.SE项目迭代一.rar
[北京圣思园Java培训教学视频]Java.SE.第一百一十九讲.Java.SE项目迭代二深度详解之系统交互.rar
[北京圣思园Java培训教学视频]Java.SE.第一百一十二讲.基于UDP的网络通信详解.续.rar
[北京圣思园Java培训教学视频]Java.SE.第一百一十五讲.Java.SE项目迭代一精讲.续.rar
As you can image,if I gonna learn the courses course-to-course.I gonna find it difficult and boring to find each them,and the sort type is not what we want. So I have to rename the file as simple as possible.
Here is just a segment code that demonstates how to use the File.renameTo(File).
文章地址https://www.yii666.com/article/764143.html文章来源地址:https://www.yii666.com/article/764143.htmlpublic static void main(String[] args) {
String path = "H:\\Java\\JavaSE\\";
File root = new File(path);
String oriName = "";
String newName = "";
String toClip = "[北京圣思园Java培训教学视频]Java.SE.";
for (String f : root.list()) {
File fSub = new File(path + f); //File to be rename(Must append from the root path).
if (!fSub.isFile()) //Only operate File.
continue;
if (fSub.getName().startsWith(toClip)) {
oriName =fSub.getName();
newName = oriName.substring(toClip.length());
File fSubNew = new File(path + newName); //The target File.
if(fSub.renameTo(fSubNew))
System.out.println(fSub.getAbsolutePath() + " rename successfully");
else
System.out.println(fSub.getAbsolutePath() + " rename failed");
}
}
}