0

我创建了一个“帮助”文本文件,当用户在我的 Java 应用程序上单击“帮助”而不打开文件选择器时,我想打开该文件。我已将帮助文件保存在与我的代码相同的位置

我的尝试:

JTextArea open = new JTextArea ();
TabPane.add ("Help", open);
open.read (new FileReader (help.txt), null);
4

1 回答 1

0

如果我让你读到你想将文件的内容显示到文本区域,对吧?

JTextArea open = new JTextArea();

BufferedInputStream inStream = new BufferedInputStream(this.getClass().getResourceAsStream("help.txt"));
    byte[] chars = new byte[1024];
    int bytesRead = 0;
    try {
        while( (bytesRead = inStream.read(chars)) > -1){
            open.append(new String(chars, 0, bytesRead));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

你可以那样做..

于 2012-03-17T14:11:18.347 回答