看视频day21-6时,毕老师的结果是:“你好”,下面我跟着敲的代码为什么读取的结果却是乱码?求教大神!
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);
String str = new String (buf,0,len);
System.out.println(str);
isr.close();
}
public static void writeText()throws IOException
{
OutputStreamWriter osw = new
OutputStreamWriter(new FileOutputStream("utf.txt"),"UTF-8");
osw.write("你好");
osw.close();
}
} |
|