当前位置: 移动技术网 > IT编程>开发语言>Java > Java批量修改文件名的实例代码

Java批量修改文件名的实例代码

2019年07月22日  | 移动技术网IT编程  | 我要评论

黑芝麻的产地,遗忘的囚室,陈国桢

复制代码 代码如下:

import java.io.*;
import java.util.*;
public class test {

    public static void main(string[] args) throws ioexception {
        bufferedreader br = new bufferedreader(new filereader("output1.txt"));
        list<string> newname = new arraylist<string>();
        list<string> oldname = new arraylist<string>();
        string line;
        string[] col;
        while((line=br.readline())!=null) {
            col = line.split("#");

            newname.add(col[0]);
            oldname.add(col[1]);
        }
        br.close();
        for(int i=0;i<newname.size();i++) {

            file oldfile = new file("d:\\tddownload\\heihei\\"+oldname.get(i)+".mp4");
            system.out.println(oldfile.exists());//看文件是否存在
            file newfile = new file(oldfile.getparent()+file.separator+newname.get(i)+".mp4");
            if(newfile.exists()) {
                system.out.println(i+"已存在");//新文件已存在
            } else {
                system.out.println(i+"\t"+oldfile.renameto(newfile));//旧文件是否重命名成功
            }
        }
    }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网