Java修改文件夹名称
学习了:http://blog.csdn.net/yongh701/article/details/45063833
进行文件夹名字批量修改,注意,要写全路径;
package com.stono.thread2.page180; import java.io.File; public class ChangeFolderName { public static void main(String[] args) { //D:JavagitworkspaceCodingsrccomstono hread2 String path = "D:\Java\gitworkspace\Coding\src\com\stono\thread2"; File root = new File(path); File[] listFiles = root.listFiles(); for (File file : listFiles) { boolean isDirectory = file.isDirectory(); String name = file.getName(); String substring = name.substring(4); if(isDirectory && name.length()==6) { System.out.println(name); System.out.println(substring); file.renameTo(new File("D:\Java\gitworkspace\Coding\src\com\stono\thread2\page0"+substring)); } } } }
如果路径中有斜线,拷贝到java字符串中,Eclipse会自动进行转义,一个变成了两个\;
修改之后,发现类里面的包名全部都错了,使用http://www.cnblogs.com/stono/p/8449285.html方法进行了类文件中包名的修改;