Java reads local UTF8 txt file garbled Processing

Source: Internet
Author: User

[Java]
Package test;
 
Import java. io. BufferedReader;
Import java. io. File;
Import java. io. FileInputStream;
Import java. io. InputStreamReader;
 
/**
* @ Author JavaAlpha 02:06:27 UTF8 txt file garbled Processing
*/
Public class QQGroup {
 
/**
* @ Param args
*/
Public static void main (String [] args ){
 
ReadTxt ();
}
 
Private static void readTxt (){
Try {
File f1 = new File ("e:/qqgroup.txt"); // open the File
FileInputStream in = new FileInputStream (f1 );
// Specify the UTF-8 format to read when reading the file
BufferedReader br = new BufferedReader (new InputStreamReader (in,
"UTF-8"); // read the file
String name = "";
String numb = "";
String str;

System. out. println ("group name ************** group number ");
While (str = br. readLine ())! = Null ){
If (str. indexOf ("class = \" addrtitle \ ">")>-1 ){
Name = str. substring (str. indexOf (">"), str. indexOf ("</"));
System. out. println ("group name:" + name );
}
If (str. indexOf ("gid =")>-1 ){
Numb = str. substring (str. indexOf ("gid ="), str. indexOf ("@ groupmail "));
System. out. println ("group number:" + numb );
}
}
In. close (); // close reading www.2cto.com
} Catch (Exception e1) {// if an error occurs, process it here
E1.printStackTrace (); // print the error message
}
}
}
Author: JavaAlpha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.