主要介绍使用java来读取txt文本文件,且每次读取2个字节,也就是采用unicode编码的文本。
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 stub
		File myfile=new File("H:/test.txt");
		//FileReader是字符流,每次读入的是两个字节。
		FileReader in=new FileReader(myfile);
		
		int test;
		while((test=in.read())!=-1)
		{
			System.out.println(test);
		}
		
		in.close();
		
	}
}
unicode编码
输出结果是:
我们发现是一样的,也就是可以正常的输出unicode编码。
原文:http://blog.csdn.net/itbuluoge/article/details/39457403