正确代码:- import java.io.*;
- class FileReaderTest
- {
- public static void main(String[] args) throws Exception
- {
- FileReader fr = new FileReader("Test.txt");
- char[] arr = new char[4];
- int len = 0;
- while((len = fr.read(arr))!=-1)
- {
- System.out.println(new String(arr,0,len));
- }
- }
- }
复制代码 错误代码:- import java.io.*;
- class FileReaderTest
- {
- public static void main(String[] args) throws Exception
- {
- FileReader fr = new FileReader("Test.txt");
- char[] arr = new char[4];
- while((int len = fr.read(arr))!=-1)
- {
- System.out.println(new String(arr,0,len));
- }
- }
- }
复制代码 问题:为什么我在while内部为len赋值就会出错??? |