修改文件和文件名

package jvmTest;
import java.io.File;
public class FileRename {
	private static void testRenameFile(String filePath) {
		try {
			File rootFile = new File(filePath);
			File[] files = rootFile.listFiles();
			for(File f:files){
				if(f.isFile()){
					String fileName = f.getName();
					if(fileName.contains("】")){ //改名规则
						String newFileName = fileName.split("】")[1];
						f.renameTo(new File(filePath+File.separator+newFileName));
					}
				}else if(f.isDirectory()){
					System.out.println(f.getAbsolutePath());
					testRenameFile(f.getAbsolutePath());
				}
			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	public static void main(String[] args) {
//		String filePath = "E:\\Vedio\\jvm\\深入理解Java虚拟机(jvm性能调优+内存模型+虚拟机原理)";
		String filePath = "E:/Vedio/jvm/深入理解Java虚拟机(jvm性能调优+内存模型+虚拟机原理)";
		testRenameFile(filePath);
	}
}

阅读更多

没有更多推荐了,返回首页