获取并解析文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public void parse() {
InputStream resource = Test.class.getResourceAsStream("/a.txt");
try {
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(resource));
// 获取文件
String line;
while ((line = bufferedReader.readLine()) != null) {
}
} catch (IOException e) {
e.printStackTrace();
}
}
获取其及子孙目录下的所有文件和目录1
2
3
4
5
6
7
8
9
10
11public static List<Path> getFileList() {
try {
return Files.walk(Paths.get(dir))
.filter(Files::isRegularFile)
.filter(e -> e.toString().contains("app"))
.collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
写入文件1
2
3
4
5
6
7
8
9
10
11
12public static void write(StringBuilder stringBuilder) {
BufferedWriter bfw = null;
try {
bfw = Files.newBufferedWriter(Paths.get(dir + "/a.txt"));
bfw.write(stringBuilder.toString());
bfw.flush();
bfw.close();
} catch (IOException e) {
e.printStackTrace();
}
}