国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java批量修改文件名的實例代碼

2019-11-26 16:11:54
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 晴隆县| 田阳县| 岑溪市| 吉木乃县| 新沂市| 新昌县| 东平县| 河北区| 中山市| 安仁县| 都江堰市| 锦州市| 黎川县| 台南县| 阳泉市| 襄汾县| 峨山| 读书| 曲沃县| 萍乡市| 博白县| 吐鲁番市| 灵石县| 甘德县| 隆回县| 博兴县| 合江县| 伊通| 依安县| 南安市| 江山市| 海林市| 开化县| 晋州市| 叙永县| 五原县| 高密市| 和田县| 三亚市| 茂名市| 屏边|