filechooser 调用showOpenDialog返回一个File类的值,用这个值创建一个输入流读取其中的内容,并写到textpane上去。

解决方案 »

  1.   

    帮人帮到底吧。JFileChooser fileChooser = new JFileChooser();
    int option = fileChooser.showOpenDialog(null);
    if(option == JFileChooser.APPROVE_OPTION)
    {
      File file = fileChooser.getSelectedFile();
      FileReader reader = new FileReader(file);
      //the following you write the processing of the reading from the reader and
      //writing them into the text pane.
      ***********
    }
      

  2.   

    你写的我都会了,没写的还是不会,象您说的帮人帮到底吧,how to processing of the reading from the reader?请您把最后的秘密告诉我吧,谢谢
      

  3.   

    int temp;
    char character;
    String text = "";while((temp = reader.read()) != -1)
    {
      character = (char)temp;
      text += character;
    }// then insert the text string into the text pane
    *****
      

  4.   

    自己写一个读文件的函数
    openFile(fileChooser.getSelectedFile().getPath())函数内容如下:
    void openFile(final String fileName)
    {
          RandomAccessFile in = new RandomAccessFile(fileName,"r");
          final int size = (int)in.length();
          byte[] data = new byte[size];
          in.read(data,0,size);
          .......
    }
    这样文件里的东西全存在了data里了,下面的操作就简单了吧!
      

  5.   

    String sourstr="";
    BufferedReader source= new BufferedReader(new FileReader(selectFile));   //设置读取文件缓冲
                  String str;
                  String sourstr=new String("");
                  while((str=source.readLine())!=null)
                     {
                        sourstr=sourstr+str+"\n";
                     }
                  jTextPane.setText(sourstr);