本帖最后由 来自沙沙的我 于 2014-5-31 16:13 编辑
- public class IO_11 {
- public static void main(String[] args) throws IOException
- {
- FileReader ty=new FileReader("D:/fdf.txt");
- char[] a1=new char[3];
- int i=0;
- while((i=ty.read(a1))!=-1)
- {
-
- System.out.println("a1[]读取数目为"+i+",为"+new String(a1));
-
- }
- ty.close();
- }
- }
复制代码
上面的代码通过且读取正确;可是下面的代码运行正常但是读取的时候混乱错误,求解为什么?
- import java.io.*;
- public class IO_11 {
- public static void main(String[] args) throws IOException
- {
- FileReader ty=new FileReader("D:/fdf.txt");
- char[] a1=new char[3];
-
- while((ty.read(a1))!=-1)
- {
- int i=ty.read(a1);
- System.out.println("a1[]读取数目为"+i+",为"+new String(a1));
-
- }
- ty.close();
- }
- }
复制代码
|
|