上代码
public class Test2 {
public static void main(String[] args) {
File file = new File("C:\\Users\\DELL\\Desktop\\qqq");
File file1 = new File("F:\\test");
if(!file1.exists()){
file1.mkdirs();
}
try {
copyFile(file,file1);
} catch (IOException e) {
e.printStackTrace();
}
changeFile(file1);
}
//修改名称
private static void changeFile(File file) {
//判断是否为文件夹
if(file.isDirectory()){
//遍历文件夹
for (File listFile : file.listFiles()) {
//判断文件夹内的文件是否以.JPG或者.jpg结尾,
if(listFile.isFile() && (listFile.getName().endsWith(".JPG") || listFile.getName().endsWith(".jpg"))){
//获取文件的绝对路径,拼成以.png结尾的字符串
String absolutePath = listFile.getAbsolutePath();
String substring = absoluteP