十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
package com.nokia;
成都创新互联专注于庐江企业网站建设,响应式网站开发,商城网站制作。庐江网站建设公司,为庐江等地区提供建站服务。全流程按需求定制网站,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务
import java.io.File;
/*
* This is class used for rename the whole file under file folder name*/
public class RenameFile {
public static void main(String args[]) {
/*
* you should change the path E://文件夹 to what you have on your own computer!*/
File fl = new File("E://文件夹"); //这里写上发替换的文件夹路径,注意使用双斜杠
String[] files = fl.list();
File f = null;
String filename = "";
for(String file:files){
f = new File(fl,file);//注意,这里一定要写成File(fl,file)如果写成File(file)是行不通的,一定要全路径
filename = f.getName();
// System.out.println(filename);
/*the string 要替换掉的内容 is the content in your own file string with the name 替换成的内容,
* here you should change the string into what you have.*/
f.renameTo(new File(fl.getAbsolutePath() + "//" + filename.replace("要替换掉的内容", "替换成的内容")));//这里可以反复使用replace替换,当然也可以使用正则表达式来替换了
}
}
}
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test
{
public static void main(String[] args) throws Exception
{
File dir = new File("d:/test");//此处表示你要改的文件所在的文件夹,也修改为其它文件夹,或者当前文件夹new File(".")
File[] files = dir.listFiles();
String fileName = null;
String parentPath = dir.getAbsolutePath();
Pattern p = Pattern.compile("广东-(广州\\d+\\.txt)");
Matcher m = null;
for (File file : files)
{
fileName = file.getName();
m = p.matcher(fileName);
if (m.matches())
{
file.renameTo(new File(parentPath + File.separator + m.group(1)));
}
}
}
}
File file = new File("D:\\temp\\A\\B\\");
for(File fl: file.listFiles()){
String flName = fl.getPath().substring(3).replace("\\", "-");
System.out.println(flName);
File newFl = new File(fl.getParent() + File.separator + flName);
System.out.println(newFl.getPath());
fl.renameTo(newFl);
}