-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchFile.java
56 lines (45 loc) · 1.41 KB
/
SearchFile.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package fileEncoding;
import java.io.File;
import java.io.IOException;
public class SearchFile {
//D:\\BaiduYunDownload\\[IT教程网]JavaSE基础视频\\Code
//D:\\Users\\javawork\\ALiBaBa
private static String dirPath = "D:\\BaiduYunDownload\\[IT教程网]JavaSE基础视频\\Code";
// private static String dirPath = "D:\\Users\\javawork\\Day20\\utfFile";
/**
* 将制定路径下所有的Java文件编码格式由GBK转为UTF-8
* 使用前请将 dirPath 改为需要操作的路径
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File dir = new File(dirPath);
search(dir);
}
private static void search(File dir) throws IOException {
String fileName = null;
File[] files = dir.listFiles();
for(int x=0; x<files.length; x++){
if(files[x].isDirectory()){
search(files[x]);
}
else{
fileName = files[x].getName();
if(JudgeFileExtensionName(fileName)){
System.out.println(fileName);
FileEncoding fileE = new FileEncoding();
fileE.transFileEncoding(files[x].getCanonicalPath());
}
}
}
}
private static boolean JudgeFileExtensionName(String fileName) {
// TODO Auto-generated method stub
// String regex = "[a-zA-z0-9]*[.][j][a][v][a]";
String regex = "[a-zA-z0-9]*[.][t][x][t]";
boolean flag = false;
flag = fileName.matches(regex);
return flag;
}
}