想要天天向上,就要懂得享受学习。图老师为大家推荐Java批量修改文件名的实例代码,精彩的内容需要你们用心的阅读。还在等什么快点来看看吧!
【 tulaoshi.com - 编程语言 】
代码如下:
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"));
        ListString newName = new ArrayListString();
        ListString oldName = new ArrayListString();
        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;inewName.size();i++) {
            File oldFile = new File("D:TDDOWNLOADheihei"+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));//旧文件是否重命名成功
            }
        }
    }
} 
来源:http://www.tulaoshi.com/n/20160219/1595097.html
看过《Java批量修改文件名的实例代码》的人还看了以下文章 更多>>