⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filerename.java

📁 this pgm renames the file
💻 JAVA
字号:
import java.io.*;   
    
public class FileRename {   
    
 public static void main(String[] args) {   
    String targetExtension=".xml";   
    if(args.length >= 1 ) {//1   
        String ext =args[0].substring(args[0].indexOf("."));   
        System.out.println(ext);   
        if(ext.equalsIgnoreCase(".txt")) {//2   
          File f = new File(args[0]);   
          //if the file exists   
          // then change the filename   
          if(f.exists()) {//3   
           args[0]=args[0].replace(ext,targetExtension);   
           System.out.println(" "+args[0]);   
           File change = new File(args[0]);   
           f.renameTo(change);   
          }//3   
          //if file does not exists then create a new file   
          else {//3   
                     try {   
            f.createNewFile();   
            args[0]=args[0].replace(ext,targetExtension);   
            System.out.println(" "+args[0]);   
    
            File change = new File(args[0]);   
    
            f.renameTo(change);   
          }//try   
          catch(IOException ioe) {   
    
          }//catch   
    
        }//3   
    
      }//2   
    
    }//1   
    
 }//main   
    
}//class   
   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -