- import java.io.*;
- class EncodeStreamDemo
- {
- public static void main(String[] args) throws IOException
- {
- //writeText();
- readText();
- }
- public static void readText() throws IOException
- {
- InputStreamReader isr = new InputStreamReader(new FileInputStream("gbk.txt"),"UTF-8");
- char [] byt = new char[10];
- int len = 0;
- int count = 0;
- while ((len =isr.read(byt))!=-1)
- {
- count++;
- String s = new String(byt,0,len);
- System.out.print(s);
- }
- System.out.println(count);
- /*
- int len = isr.read(byt);
- String s = new String(byt,0,len);
- System.out.println(s);
- isr.close();
- */
- }
- public static void writeText() throws IOException
- {
- OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("utf.txt"),"UTF-8");
- osw.write("你好");
- osw.close();
- }
- }
复制代码
这段代码执行后为什么count的值是2 意思是为什么循环2次
|