0

私はチャートを表示するためのアプリケーションを書いています。GWT Highcharts (Moxie Group による) を使用して結果を表示しています。チャートに乱数を追加すると、問題なく動作します。

しかし、テキストファイルから数値をロードしたいです。ファイルの内容を読み取って、配列などに配置したいだけです。Javaでこれを行うにはどうすればよいですか?

4

1 に答える 1

0

以下のような小さなプログラムを使用して、それを実現できます。

GWT ハイチャートで必要な方法で要素を読み取るには、ロジックを変更する必要がある場合があります。

public class ReadATextFile {
    public static void main(String[] args) {
        try (RandomAccessFile readFile = new RandomAccessFile("C:\\Test.txt", "r");) {
            int EOF = (int) readFile.length();
            System.out.println("Length of the file is (" + EOF + ") bytes");
            //Considering to read the first 150 bytes out of 168 bytes on the file
            readFile.seek(0);
            byte[] bytes = new byte[EOF];

            readFile.readFully(bytes);
            readFile.close();

            System.out.println(new String(bytes));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

Test.txt ファイルの内容は次のようになります。

1 2 3 4
5 6 7 8
9 10 11
于 2016-02-11T11:37:03.953 に答える