本帖最后由 ″先森丶玹° 于 2013-11-30 22:05 编辑
-
- public static void writeCode() throws IOException {
- OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("D:\\IO测试专用\\其他流\\change.txt"),"GBK");
-
- osw.write("编程思想");
-
- osw.close();
-
- }
-
- public static void readCode() throws IOException {
- InputStreamReader isr=new InputStreamReader(new FileInputStream("D:\\IO测试专用\\其他流\\change.txt"),"GBK");
-
- char[] buf=new char[1024];
-
- int length=isr.read(buf);
-
- sop(new String(buf,0,length));
-
- isr.close();
- }
复制代码
问题:为什么int length=isr.read(buf);
sop(new String(buf,0,length));
这里不需要用while循环来读取?
while((length.read(buf))!=-1){
sop(new String(buf,0,length));}
这样的 |