本文實例講述了java實現(xiàn)批量修改txt文件名稱的方法。分享給大家供大家參考,具體如下:
最近在做特征選擇的實驗時,需要批量修改一下文件名稱,在這里做一下記錄。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package com.cqu.experiment; import java.io.file; /** * @author 作者: e-mail:@126.com * @version 創(chuàng)建時間:2016年12月26日 下午3:02:01 類說明 */ public class renametxt { public static void renametxt(file file) { if (file.isdirectory()) { file[] files = file.listfiles(); system.out.println(files.length); for (file f : files) { system.out.println(f.getname()); string originalname = f.getname(); system.out.println(originalname); string newname = "10" + originalname; string newfilepath = "f:\\develop_code\\workspace\\research\\3.特征選擇\\trainingset\\c000010" ; file newfilename = new file(newfilepath + "\\" + newname); synchronized (f) { f.renameto(newfilename); } } } } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
package com.cqu.experiment; import java.io.file; /** * @author 作者: e-mail:@126.com * @version 創(chuàng)建時間:2016年12月26日 下午3:01:46 * 類說明 */ public class main { public static void main(string[] args) { string dir = "f:\\develop_code\\workspace\\research\\c000010" ; file file = new file(dir); file[] files = file.listfiles(); renametxt.renametxt(file); } } |
希望本文所述對大家java程序設計有所幫助。
原文鏈接:https://blog.csdn.net/u013272948/article/details/53887001