复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22public static void main(String arg[]) throws Exception { /* 读入TXT文件 */ URL url = LikeTagsServiceImpl.class.getClassLoader().getResource("11.txt"); File filename = new File(url.getPath()); // 建立一个输入流对象reader InputStreamReader reader = new InputStreamReader(new FileInputStream(filename), "UTF-8"); // 建立一个对象,它把文件内容转成计算机能读懂的语言 BufferedReader br = new BufferedReader(reader); String line = ""; line = br.readLine(); HashSet<String> hashSet = new HashSet<String>(4096); while (line != null) { // 一次读入一行数据 line = br.readLine(); if (StringUtils.isBlank(line)) { continue; } hashSet.add(line); } System.out.println(hashSet.size()); System.out.println(hashSet.toString()); }
最后
以上就是爱笑棒棒糖最近收集整理的关于java读取txt文件数据的全部内容,更多相关java读取txt文件数据内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复