日期:2014-05-20 浏览次数:20731 次
package com.study.test;
import java.io.File;
public class Test {
public static void main(String[] args) {
File file = new File("D:\\1");
reName(file);
}
public static void reName(File file){
if(file.isDirectory()){
File[] files = file.listFiles();
for(File f : files){
reName(f);
}
}else{
String fileName = file.getName();
String ex = fileName.substring(fileName.lastIndexOf("."));
fileName = fileName.substring(0, fileName.lastIndexOf("."));
fileName = fileName.replaceAll("\\.", "_");
file.renameTo(new File(file.getParent() + File.separator + fileName + ex));
}
}
}
public class StackWord {
public static void main(String[] args){
subString("D:\\log");
}
public static void subString(String filePath){
File file = new File(filePath);
File [] filelist = file.listFiles();
for(int i=0;i<filelist.length;i++){
String str = filelist[i].getName().substring(filelist[i].getName().lastIndexOf("."));
System.out.println(filelist[i].getName().substring(0, filelist[i].getName().length()-str.length()));
}
}
}