private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        JFileChooser fileChooser=new JFileChooser();
        fileChooser.showOpenDialog(null);
       File file = fileChooser.getSelectedFile(); 
       String str1=file.getAbsolutePath();
        try {
          jTextArea1.read(new FileReader( file.getAbsolutePath()), null );
        } catch (IOException ex) {
          //System.out.println("problem accessing file"+file.getAbsolutePath());
        }
    }

解决方案 »

  1.   

    [code=Java]
    package Test;import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;public class Ggz { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new Ggz().jMenuItem6ActionPerformed();
    } JTextArea jTextArea1 = new JTextArea(); 

    private void jMenuItem6ActionPerformed() {
      // TODO add your handling code here:
    JFrame jframe = new JFrame(); 
      JFileChooser fileChooser=new JFileChooser();
      fileChooser.showOpenDialog(null);
      File file = fileChooser.getSelectedFile();  
      String str1=file.getAbsolutePath();
      try {   jTextArea1.read(new FileReader( file.getAbsolutePath()), null );
      System.out.println(jTextArea1.getLineCount());
      jframe.add(jTextArea1);
      jframe.setVisible(true);
      } catch (IOException ex) {
      //System.out.println("problem accessing file"+file.getAbsolutePath());
      }
      }
    }[/code试过了没有问题
      

  2.   


    package Test;import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;public class Ggz { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new Ggz().jMenuItem6ActionPerformed();
    } JTextArea jTextArea1 = new JTextArea(); 

    private void jMenuItem6ActionPerformed() {
      // TODO add your handling code here:
    JFrame jframe = new JFrame(); 
      JFileChooser fileChooser=new JFileChooser();
      fileChooser.showOpenDialog(null);
      File file = fileChooser.getSelectedFile();  
      String str1=file.getAbsolutePath();
      try {   jTextArea1.read(new FileReader( file.getAbsolutePath()), null );
      System.out.println(jTextArea1.getLineCount());
      jframe.add(jTextArea1);
      jframe.setVisible(true);
      } catch (IOException ex) {
      //System.out.println("problem accessing file"+file.getAbsolutePath());
      }
      }
    }