功能

可以根据使用路径修改文件名,已经测试,可以成功运行

思路

先是读取到txt文本文件,之后使用String的spilt进行分割,每一行的格式为 旧名字 新名字,中间的空格可以使用|或者其他字符代替,以此为标志分割String

之后将旧名字当做key,新名字当做value写入到map中去

获得文件的所在的文件夹,listFile遍历得到所有的文件,之后getName获得文件名(这里获得到的文件名是包括有扩展名的)

再次使用String的spilt进行处理(参数为"\.",需要转义),得到文件名和扩展名

reName改名字,参数为一个文件对象

代码

先把代码贴出来吧,之后再做个有界面的工具~

	class Test {

		private static Map<String, String> map;

		public static void main(String[] args) {
map = readTxtFile("T:\\游戏资源\\仙剑4\\音乐目录.txt");
reName("T:\\游戏资源\\仙剑4\\仙剑奇侠传四音乐"); } /**
*
* @param s 文件所在文件夹路径名
*/
public static void reName(String s){
File file = new File(s);
if (file.isDirectory()){
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
String h = files[i].getName();
String[] temp = h.split("\\.");
String newName = map.get(temp[0]);
files[i].renameTo(new File(s+"\\"+newName+"."+temp[temp.length-1]));
}
}
}
private static HashMap<String, String> readTxtFile(String filePath){
HashMap<String, String> map = new HashMap<>();
try {
String encoding="GBK";
File file=new File(filePath);
if(file.isFile() && file.exists()){ //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = bufferedReader.readLine()) != null){
String[] split = lineTxt.split(" ");
map.put(split[0],split[1]);
}
read.close();
}else{
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
return map;
}
}

Java小工具 根据文本批量修改文件名的更多相关文章

  1. 使用Java中File类批量创建文件和批量修改文件名

    批量创建文件 int cont = 1; String s = "E:\\学习资料\\Java笔记-"; while(cont<100){ File f = new File ...

  2. rename 批量修改文件名

    1.rename的用法 rename与mv的区别就是mv只能对单个文件重命名,而rename可以批量修改文件名 linux中的rename有两种版本,一种是C语言版的,一种是Perl版的.早期的Lin ...

  3. Linux下find一次查找多个指定类型文件,指定文件或者排除某类文件,在 GREP 中匹配多个关键 批量修改文件名等

    http://blog.sina.com.cn/s/blog_62e7fe670101dg9d.html linux下二进制文件查找: strings 0000.ts | grep -o " ...

  4. [转载][记录]shell 批量修改文件名

    参考了:[新手入门] shell脚本批量修改文件名 4楼回复 我刚好是在vagrant+ubuntu中进行开发,windows手动修改太麻烦. #!/bin/ksh ls *.htm | while ...

  5. linux批量修改文件名的shell脚本

    linux中批量修改文件名的shell脚本代码,主要是使用了rename,结合shell,喜欢的朋友可以参考下 使用 rename 命令  ========================  NAME ...

  6. 用python批量修改文件名

    从youtube上当下来百来首mv,每个都需要去掉视频,这还挺好弄得,格式工厂一弄就完了,但是文件名,都带有乱七八糟的*啥的巴拉巴拉的,咋修改啊,几百首总不可能一个一个rename吧 #批量修改文件名 ...

  7. windows下如何批量修改文件名

    windows下如何批量修改文件名 一.总结 一句话总结:就是用excel生成了多条修改文件名的dos命令然后执行,比较核心的就是把图片名称导入excel 将图片名称导入excel---编写如下DOS ...

  8. C# 批量修改文件名

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. Linux下批量修改文件名(rename)

    原文地址: http://blog.csdn.net/sea_shore/article/details/6102437 1.rename命令批量修改文件名, 其实linux下可以使用别的办法来批量修 ...

随机推荐

  1. 压力测试工具 ab

    ab 是Apache 自带的一个压力测试工具,命令行,是 ApacheBench 命令的缩写. ab的原理:ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问.它的测试目标是基 ...

  2. DOS命令(一)

    1. echo 输出内容,用来输出文字. [例如:echo hello] 2. titile 标题,用来修改标题. 3. color 背景色前景色,用来设置背景色和前景色 0 = 黑色 8 = 灰色 ...

  3. Ajax刷新DIV内容

    Ajax刷新DIV内容 实现了网页的异步数据处理,不用刷新整个页面 <标签 onmouseover="method"/ >method:这个参数是处理onmouseov ...

  4. github pages + Hexo + node.js 搭建属于自己的个人博客网站

     之前我写过一篇用Github实现个人主页的博客:https://www.cnblogs.com/tu-0718/p/8081288.html   后来看到某个大佬写的文章:[5分钟 0元搭建个人独立 ...

  5. [Swift]LeetCode115. 不同的子序列 | Distinct Subsequences

    Given a string S and a string T, count the number of distinct subsequences of S which equals T. A su ...

  6. [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...

  7. [Swift]LeetCode438. 找到字符串中所有字母异位词 | Find All Anagrams in a String

    Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...

  8. iOS——调试工具LLDB学习

    一.前言 LLDB是个开源的内置于XCode的具有REPL(read-eval-print-loop)特征的Debugger,其可以安装C++或者Python插件.在日常的开发和调试过程中给开发人员带 ...

  9. 面试中程序员常见的Redis"刁难"问题,值得一读!

    导读 在程序员面试过程中Redis相关的知识是常被问到的话题.作为一名在互联网技术行业打击过成百上千名的资深技术面试官,总结了面试过程中经常问到的问题.十分值得一读. Redis有哪些数据结构? 字符 ...

  10. ThinkPHP 数据库操作(三) : 查询方法、查询语法、链式操作

    查询方法 条件查询方法 where 方法 可以使用 where 方法进行 AND 条件查询: Db::table('think_user') ->where('name','like','%th ...