本帖最后由 我为你着迷 于 2014-12-22 13:51 编辑
- 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("utf.txt"),"utf-8");
-
- 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();
- }
- }
复制代码 大家好 我想问下这句话char[] buf=new char[10]; 为什么用的是字符数组呢 而不是字节数组呢?byte[] buf=new byte[10];
这不是在操作字节读取流对象呢? 哪位帮小弟解答下 好吗 黑马币无限给你!
|