0%

java读目录里所有文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package site.xixing.io;

import java.io.File;

/**
* @author xixing
* @version 1.0
* @date 2020/5/31 8:03
*/
public class ReadDirectory {

public static void main(String[] args) {
File file=new File("D:\\wx");
File[] files = file.listFiles();
for (File file1 : files) {
String substring = file1.getName().substring(2);
String newFilePath=file1.getParent()+File.separator+substring;
File newFile=new File(newFilePath);
file1.renameTo(newFile);

}
}
}