文件移动以及重命名

package com.coding;

import java.io.File;

public class Test23 {

public static void main(String[] args) {

String[] fileNameArr = {"01.jpeg", "02.jpeg", "03.jpeg", "04.jpeg", "05.jpeg"};

Test23 test23 = new Test23();
for (int i = 0; i < fileNameArr.length; i++) {
test23.moveFile(fileNameArr[i]);
}

}

private void moveFile(String fileName) {

String oldFilePath = "D:\\test\\move01\\";
String newFilePath = "D:\\test\\move02\\";

File oldFile = new File(oldFilePath + fileName);

String fileType = fileName.substring(fileName.lastIndexOf("."), fileName.length());
String fileNameStr = fileName.substring(0, fileName.lastIndexOf("."));
File newFile = new File(newFilePath + fileNameStr + "aaa" + fileType);

oldFile.renameTo(newFile);

}
}

posted on   ~码铃薯~  阅读(27)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-02-18 新年开工第一天,登录堡垒机出现问题 Shterm
2021-02-18 IDEA Junit单元测试System.in 没办法输入
2020-02-18 (十二)MySQL语法-外连接关系图谱
2020-02-18 (十一)MySQL语法-外连接
2020-02-18 公司框架-微服务-代码修改
2020-02-18 公司框架-微服务-从前端找到后端

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示