Java代码 文件改名 _改名 文件改名 _改名_02

  1.  
  2. import java.io.File;
  3. import java.net.URI;
  4. import java.net.URISyntaxException;
  5. import java.net.URL;
  6.  
  7.  
  8. public class RollDateFile {
  9.  
  10. public static void rename(File f,String old_v,String new_v ){
  11. if(f.isDirectory()){
  12. for(File file :f.listFiles()){
  13. rename(file,old_v,new_v );
  14.  
  15. }
  16. }else{
  17. String path = f.getParent();
  18. String newFile = (f.getName()+"").replaceAll(old_v,new_v);
  19. String newF = path+File.separator+newFile;
  20. System.out.println(newF);
  21. f.renameTo(new File(newF));
  22. }
  23. }
  24.  
  25. /**
  26. * @param args
  27. * @throws Exception
  28. */
  29. public static void main(String[] args) throws Exception {
  30. // TODO Auto-generated method stub
  31. String path ="E:\\a\\";
  32. String old_value ="20120828";
  33. String new_value ="20130124";
  34. File folder = new File(path);
  35. rename(folder,old_value,new_value);
  36. }
  37.  
  38. }