我想读取一个文件
正确写法是这样:- import java.io.*;
- class FileReaderTest
- {
- public static void main(String[] args) throws IOException
- {
- FileReader fr = new FileReader("FileWriterAgain.java");
- char[] arr = new char[1024];
- int len =0;
- while((len=fr.read(arr))!=-1)
- {
- System.out.print(new String(arr,0,len));
- }
- fr.close();
- }
- }
复制代码 错误写法这样:- import java.io.*;
- class FileReaderTest
- {
- public static void main(String[] args) throws IOException
- {
- FileReader fr = new FileReader("FileWriterAgain.java");
- char[] arr = new char[1024];
- while((int len = fr.read(arr))!=-1)
- {
- System.out.println(new String(arr,0,len));
- }
- fr.close();
- }
- }
复制代码 问题:我想问为什么第二种写法是错误的?? |