2

了解しました。テキストファイルを読み込もうとしています。次に、それをプロセステーブルのarraylist内のプロセスを実際に表す行に分割します。次に、行内のすべてのトークンを分割し、行のすべてのトークンを再び配列リストにします。これまでのところ、これですべてです。

正しく機能していません。私は得ています:

processes:[[netscape, 1, 00ACF3, 20990, 12DFFE, 000F00, 000000, 000000, 000000, AF,   011356, 000000, 000000, 4FFFFF, 39AB00, 000000, 0A0B92, FFFFFF]]
processes:[[netscape, 1, 00ACF3, 20990, 12DFFE, 000F00, 000000, 000000, 000000, AF, 011356, 000000, 000000, 4FFFFF, 39AB00, 000000, 0A0B92, FFFFFF, textpad, 2, 391BCA, 871BAF, DEA14C, EEFC30, 000000, 000000, 0000AA, AF, 000000, 000000, 000000, 000000, 000000, FFFFFF, B4344D, 000000], [netscape, 1, 00ACF3, 20990, 12DFFE, 000F00, 000000, 000000, 000000, AF, 011356, 000000, 000000, 4FFFFF, 39AB00, 000000, 0A0B92, FFFFFF, textpad, 2, 391BCA, 871BAF, DEA14C, EEFC30, 000000, 000000, 0000AA, AF, 000000, 000000, 000000, 000000, 000000, FFFFFF, B4344D, 000000]]

BufferedReader inputStream = null;
ArrayList<ArrayList<String>> lines = new ArrayList<ArrayList<String>>();
ArrayList<String> tokens = new ArrayList<String>();
/* read the file*/
try {
    inputStream = new BufferedReader(new FileReader("p56.txt"));

    while (true) {
        /* while the file was read*/
        /* now. split the file into the lines.*/
        String line = inputStream.readLine();
        if (line == null) {
            break;
        }
        //if there are no more lines left. break

        // split the lines into tokens and make into an arraylist*/
        Scanner tokenize = new Scanner(line);
        while (tokenize.hasNext()) {
            /*while there are still more*/
            tokens.add(tokenize.next());
        }
        lines.add(tokens);

        System.out.println("processes:" + lines);
    }
}
4

1 に答える 1

1

行を移動する必要があります

ArrayList<String> tokens = new ArrayList<String>();

直前に

while (tokenize.hasNext()) {

次に、各行を処理する前に、トークンの新しいリストを作成します。そうしないと、ファイルのすべての行のすべてのトークンのリストが表示されます。

于 2010-10-02T18:12:56.430 に答える