java--swing在文本框显示某txt文件内容..

从http://qzone.qq.com/blog/120824770-1213725887转过来的

public class frm_text extends JFrame { 
    File f1;//io包的....自己查帮助 
    BufferedReader in = null; 
    JPanel contentPane; 
    JTextArea jTextArea1 = new JTextArea(); 
    TitledBorder titledBorder1 = new TitledBorder(""); 
    JButton jButton1 = new JButton(); 
    public frm_text() { 
        try { 
            setDefaultCloseOperation(EXIT_ON_CLOSE); 
            jbInit(); 
            f1 = new File("test.txt"); 
            in = new BufferedReader(new FileReader(f1)); 
            jTextArea1.setText("文件名:" + f1.getName() + "\n"); 
            jTextArea1.append("父目录:" + f1.getParent() + "\n"); 
            jTextArea1.append("最后修改日期:" + f1.lastModified() + "\n"); 
            jTextArea1.append("长度:" + f1.length() + "\n"); 
            jTextArea1.append("绝对路径:" + f1.isAbsolute() + "\n"); 
            jTextArea1.append("\n文件内容:"); 
            String str1 = in.readLine(); 
            while (str1 != null) { 
                jTextArea1.append("\n"+str1); 
                str1 = in.readLine(); 
            } 
        } catch (Exception exception) { 
            exception.printStackTrace(); 
        } 
    } 

你可能感兴趣的:(java,swing,qq,Blog)