package test; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; /** * @author JavaAlpha 2012-7-12下午02:06:27 UTF8 txt文件乱码处理 */ public class QQGroup { /** * @param args */ public static void main(String[] args) { readTxt(); } private static void readTxt() { try { File f1 = new File("e:/qqgroup.txt");// 打开文件 FileInputStream in = new FileInputStream(f1); // 指定读取文件时以UTF-8的格式读取 BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); // 读取文件,UTF8,不要加- String name = ""; String numb = ""; String str; System.out.println("群名*************群号"); while ((str = br.readLine()) != null) { if (str.indexOf("class=\"addrtitle\">")>-1) { name = str.substring(str.indexOf(">"), str.indexOf("</")); System.out.println("群名:" + name); } if (str.indexOf("gid=")>-1) { numb = str.substring(str.indexOf("gid="), str.indexOf("@groupmail")); System.out.println("群号:" + numb); } } in.close();// 关闭读取 } catch (Exception e1) {// 如果有错误,这里进行处理 e1.printStackTrace();// 打印错误信息 } } }