import java.io.FileReader;
public class FileReaderTest2 {
/**
* 读取bufferedReader1.java文件,打印在控制台上。
*
*
* */
public static void main(String[] args) throws Exception
{
FileReader fr = new FileReader("D:\\workspace\\IO\\src\\BufferedReader1.java");
char[] buf = new char [1024];
int len= 0;
while((len = fr.read(buf))!= -1);
{
System.out.println(new String(buf,0,len));
}
fr.close();
}
}
为什么会角标越界呢?
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.<init>(String.java:195)
at T.main(T.java:12)
|
|