珠鋒Web前端高級(jí)2022
? // 統(tǒng)計(jì)一個(gè)文件的單詞
? ?private Map<String, Long> count(File file) {
? ? ? ?String str;
? ? ? ?try {
? ? ? ? ? ?str = new String(Files.readAllBytes(file.toPath()));
? ? ? ?} catch (IOException e) {
? ? ? ? ? ?throw new RuntimeException(e);
? ? ? ?}
? ? ? ?return Stream.of(str.split("//s+")).collect(Collectors.groupingBy(word -> word, Collectors.counting()));
? ?}}
標(biāo)簽: