报错 java.lang.StringIndexOutOfBoundsException

package Test;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ReadFileData {
 public static void main(String ags[]){
  int b;
  Label lab;
  TextArea textArea;
  byte temp[]=new byte[100];
  Frame window=new Frame();window.setSize(400,400);
  lab=new Label();
  lab.setText("文件d:/write.txt的内容如下:");textArea=new TextArea(10,16);
  window.add(lab,BorderLayout.NORTH);window.add(textArea,BorderLayout.CENTER);
  window.validate();window.setVisible(true);
  window.addWindowListener(new WindowAdapter()
    {
   public  void windowClosing(WindowEvent e){
    System.exit(0);
   }
    });
  try{
   File f=new File("D:/迅雷下载/test.txt");
   FileInputStream readfile=new FileInputStream(f);
   while((b=readfile.read(temp,0,100))!=1){
    String s=new String(temp,0,b);
    textArea.append(s);
   }
   readfile.close();
  }
  catch(IOException e){
   lab.setText("文件打开错误");
  }
 }
}

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 at java.lang.String.checkBounds(Unknown Source)
 at java.lang.String.<init>(Unknown Source)
 at Test.ReadFileData.main(ReadFileData.java:29)

浮世之绘0
浏览 3453回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java