package nathan.qq.groupfriend;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.mindview.util.TextFile;
public class GroupFirendExport {
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir"));
String filePath = System.getProperty("user.dir")
+ "\\src\\nathan\\qq\\groupfriend\\friends.txt"; // 保存为GBK
Set<String> friends = new HashSet<String>();
TextFile tf = new TextFile(filePath);
for (String s : tf) {
if (s.startsWith("消息对象")) {
friends.add(s.substring(s.indexOf(":") + 1).trim());
}
}
List<String> list = new ArrayList<String>(friends);
Collections.sort(list);
exportHtmlFile(list);
}
private static void exportHtmlFile(Collection<String> friends) {
String html = "<html><body><table border='1'>";
for (String s : friends) {
html += ("<tr><td>" + s + "</td></tr>");
}
html += "</table></body></html>";
TextFile.write(System.getProperty("user.dir") + "\\friends.html", html);
}
}
其中TextFile类来自《java 编程思想 4》