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.