Java reads local utf8 TXT file garbled Processing

Source: Internet
Author: User
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 to read bufferedreader in UTF-8 format when reading a file 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 read} catch (exception E1) {// if an error occurs, handle e1.printstacktrace () here; // print the error message }}}

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.