zoukankan      html  css  js  c++  java
  • Java 批量修改文件后缀

    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");  
      }  
    }
  • 相关阅读:
    PatentTips
    PatentTips
    PatentTips
    Xvisor ARM32 启动分析
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
  • 原文地址:https://www.cnblogs.com/rojas/p/4395535.html
Copyright © 2011-2022 走看看