zl程序教程

您现在的位置是:首页 >  后端

当前栏目

JAVA文件重命名详解编程语言

JAVA文件编程语言 详解 重命名
2023-06-13 09:20:47 时间
import org.apache.tools.ant.taskdefs.Expand; import org.apache.tools.ant.taskdefs.Zip; import org.apache.tools.ant.types.FileSet; public class Test { public static void main(String[] args) { renameFile("E:/examineePhoto", "123.jpg", "1234.jpg"); public static void renameFile(String path, String oldname, String newname) { if (!oldname.equals(newname)) {// 新的文件名和以前文件名不同时,才有必要进行重命名 File oldfile = new File(path + "/" + oldname); File newfile = new File(path + "/" + newname); if (!oldfile.exists()) { return;// 重命名文件不存在 if (newfile.exists())// 若在该目录下已经有一个文件和新文件名相同,则不允许重命名 System.out.println(newname + "已经存在!"); else { oldfile.renameTo(newfile);

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16335.html

cjava