filerename.java
来自「this pgm renames the file」· Java 代码 · 共 45 行
JAVA
45 行
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 + =
减小字号Ctrl + -
显示快捷键?