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();// 关闭读取
} catch (Exception e1) {// 如果有错误,这里进行处理
e1.printStackTrace();// 打印错误信息
}
}
}
Java 读取本地 UTF8 txt文件乱码处理
最新推荐文章于 2024-08-20 04:38:40 发布
本文提供了一个使用Java语言处理UTF-8编码的文本文件的示例代码,通过该示例可以学习如何正确地读取并解析含有特定格式的文本文件。
3777

被折叠的 条评论
为什么被折叠?



