67,515
社区成员
发帖
与我相关
我的任务
分享
String[] cmds = new String[]{"mv","/home/aaa/a01 1.txt","/home/aaa/a01.txt"};
Process ps = Runtime.getRuntime().exec(cmds);
import java.io.File;
/**
* @author troy(J2EE)
* @version 1.0 1995年的3月23日
*/
public class Test {
public static void main(String[] args) {
File file = new File("/home/tomcat/tmp/1 这是一个测试文件.txt");
File file2 = new File("/home/tomcat/tmp/1.txt");
boolean success = file.renameTo(file2);
if (!success) {
System.out.println("重命名失败");
} else {
System.out.println("重命名成功");
}
}
import java.io.File;
/**
* @author troy(J2EE)
* @version 1.0 1995年的3月23日
*/
public class Test {
public static void main(String[] args) {
File file = new File("d:\\1 这是一个测试文件.txt");
File file2 = new File("d:\\2.txt");
boolean success = file.renameTo(file2);
if (!success) {
System.out.println("重命名失败");
} else {
System.out.println("重命名成功");
}
}
}
public class Test {
public static void main(String[] args) {
try {
String[] commd={"mv","/home/tomcat/tmp/1 name.txt","/home/tomcat/tmp/2.txt"};
Process p = Runtime.getRuntime().exec(commd);
p.destroy();
} catch (Exception e ) {
e.printStackTrace();
}
}
}