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 に答える