本帖最后由 Angel若梦 于 2016-10-15 23:18 编辑
[Java] 纯文本查看 复制代码 package com.heima.test;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedHashSet;
public class Test4 {
public static void main(String[] args) throws IOException {
ArrayList<String> al = new ArrayList<>();
BufferedReader br = new BufferedReader(new FileReader("a.txt"));
String data;
while ((data = br.readLine()) != null) {
al.add(data);
}
br.close();
LinkedHashSet<String> lhs = new LinkedHashSet<>();
for (String s : al) {
String[] sarr = s.split(",");
for (String s2 : sarr) {
lhs.add(s2);
}
}
PrintStream ps = new PrintStream(new FileOutputStream("b.txt"));
for (String s : lhs) {
ps.println(s);
}
ps.close();
}
}
|