2025-02-10

[java]
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")); // 讀取文件 
            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();// 關閉讀取   www.aiwalls.com
        } catch (Exception e1) {// 如果有錯誤,這裡進行處理 
            e1.printStackTrace();// 打印錯誤信息 
        } 
    } 

作者:JavaAlpha

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *