码迷,mamicode.com
首页 > 编程语言 > 详细

Java 批量修改文件后缀

时间:2015-04-06 11:25:31      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

import java.io.*;  
 
public class test {  
   
  public void reName(String path, String from, String to) {  
    File f = new File(path);  
    File[] fs = f.listFiles();  
  
    for (int i = 0; i < fs.length; ++i) {  
      File f2 = fs[i];  
     
      if (f2.isDirectory()) {  
        reName(f2.getPath(), from, to);  
      } else {  
        String name = f2.getName();
          if (name.endsWith(from)) {  
          f2.renameTo(new File(f2.getParent() + "/" + name.substring(0, name.indexOf(from)) + to));  
        }  
      }  
    }  
  }  
  public static void main(String[] args) {  
   test rf = new test();  
    rf.reName("C:/Documents and Settings/xxxxx/Desktop/astaxie", ".md",".txt");  
  }  
}

 

Java 批量修改文件后缀

标签:

原文地址:http://www.cnblogs.com/rojas/p/4395535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!