首页 > 其他 > 详细

如何给文件重命名

时间:2020-12-15 15:09:43      阅读:26      评论:0      收藏:0      [点我收藏+]
 public void fileRename(String tmpFilePath){
        String[] fileType = fileName2.split("\\.");
        File file = new File(tmpFilePath+"\\"+fileName2);
        if (file.exists()){
            String newFileName = fileType[0]+"-"+id2+"."+fileType[fileType.length-1];
            file.renameTo(new File(tmpFilePath+"\\"+newFileName));
            href = href+id2+"/media";
            HttpPostWithJson(href, JSON.toJSONString("http://192.168.6.174:8889/ProjectFiles/UploadFile/"+newFileName));
            File file1 = new File("D:\\IdeaProjects\\toolupload\\log\\confFile\\"+fileName2+".conf");
            file1.delete();
        }

    }

关键为renameTo方法

如何给文件重命名

原文:https://www.cnblogs.com/psyduck/p/14138052.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!