手机
当前位置:查字典教程网 >编程开发 >Java >Java批量修改文件名的实例代码
Java批量修改文件名的实例代码
摘要:复制代码代码如下:importjava.io.*;importjava.util.*;publicclassTest{publicstati...

复制代码 代码如下:

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: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));//旧文件是否重命名成功

}

}

}

}

【Java批量修改文件名的实例代码】相关文章:

java中通用的线程池实例代码

struts2单个文件上传的两种实现方式

移动指定文件夹内的全部文件

java使用randomaccessfile在文件任意位置写入数据

java多线程复制文件的实例代码

Java生成PDF文件的实例代码

java中 spring 定时任务 实现代码

Java实现的基于socket通信的实例代码

java对指定目录下文件读写操作介绍

java匿名内部类实例简析

精品推荐
分类导航