本文共 794 字,大约阅读时间需要 2 分钟。
//IO流-字符编码表转换示例import java.io.*;class EncodeStream { public static void main(String[] args) throws IOException { //writeText(); readText(); } public static void readText() throws IOException { InputStreamReader isr = new InputStreamReader(new FileInputStream("gbk.txt"),"gbk"); char[] buf = new char[10];//作为缓冲区 int len = isr.read(buf); /* int read(char[] cbuf, int offset, int length) 将字符读入数组中的某一部分。 */ String str = new String (buf, 0 ,len); System.out.println(str); isr.close(); } public static void writeText() throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new FileOuptStream("UTF.txt"),"utf-8"); osw.write("你好"); osw.close(); }}
转载地址:http://yzzvb.baihongyu.com/