It is no exaggeration to say that Java is one of the best language in the world rather than PHP~.
I got some study resources from a Java Wechat group about Tanhua series of ITHEIMA.The content is closed to porn topic to attract students’ interests,yeah,that is funny.
First and foremost,I directly downloaded it from Bilibili.com to avoid they may be reported by someone in the future.
Here it is the problem I met. The length of name of the videos I got from Bili Helper is too long to read.Thereby, I need to try some methods to deal with a batch of them.
That’s why I would like to use File.Class to rename.
let’s go straight to the codes
@Test
void test22222() {
File f = new File("D:\\v");
File fs[] = f.listFiles();
for (int i = 0; i < fs.length; i++) {
String name = fs[i].getName();
String replace=name.replace("探花交友_精通Spring_Cloud_Alibaba_Dubbo一栈式微服务架构,即时通讯、人脸识别等五大解决方案全掌握," +
"工作时拿来即用_黑马最新高级课程.", "");
File newFile = new File("D:\\v\\" + replace);
fs[i].renameTo(newFile);
}
}
import java.io.File;
/**
* @Description:${<VARIABLE_NAME>}
* @Author:Spike Wong
* @Date:2022/6/16
*/
public class RenameFileUtil {
//私有构造器
private RenameFileUtil() {
}
/**
* 更改文件的重复信息
*
* @param filePath
* @param target
* @param replacement
*/
public static void replaceName(String filePath, String target, String replacement) {
File f = new File(filePath);
File fs[] = f.listFiles();
for (int i = 0; i < fs.length; i++) {
String name = fs[i].getName();
String replace = name.replace(target, replacement);
File newFile = new File(filePath + File.separator + replace);
fs[i].renameTo(newFile);
}
}
}
Here is the effect of the util.
Ok, see you next time~ I will miss you dear.