Java reads unicode files

Source: Internet
Author: User

Java reads unicode files

This section describes how to use java to read txt text files, and read 2 bytes each time, that is, unicode-encoded text.

FileMain

Package com. test. filetest; import java. io. file; import java. io. fileNotFoundException; import java. io. fileReader; import java. io. IOException; public class FileMain {/*** @ param args * @ throws IOException */public static void main (String [] args) throws IOException {// TODO Auto-generated method stubFile myfile = new File ("H:/test.txt"); // FileReader is a batch stream and each read two bytes. FileReader in = new FileReader (myfile); int test; while (test = in. read ())! =-1) {System. out. println (test) ;}in. close ();}}

Txt file



Unicode encoding <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140922/20140922085706203.png" alt = "\">


The output result is:



We found that it is the same, that is, it can normally output unicode encoding.

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.