0

「filename」というtxtファイルがあるとします。内部のデータは次のとおりです。

N
12  39
34  23
12  22
5   7
7   10
11  8
  .
  .
  .

左の列には、各ポイントの x 値が含まれます。右の列には、各ポイントの y 値が含まれます。N は、後続のポイント データの行数です。すべてのポイント データを抽出し、データ構造 (リストなど) に格納する必要があります。それを行う方法はありますか?

4

2 に答える 2

2
File file = new File(filepath);
BufferedReader br = new BufferedReader(file.getInputStream);
int n = Integer.parseInt(br.readLine());

for (int i = 0; i < n-1; i++) // reads n-1 points, if you have n points to read, use n instead of "n-1"
{
    line = br.readLine();
    StringTokenizer t = new StringTokenizer(line, " ");

    int x = Integer.parseInt(t.nextToken());
    int y = Integer.parseInt(t.nextToken());

    // do whatever with the points
}

これは、入力ファイルとして次のようなもので機能します。

3           // line 1 
1 2         // line 2
3 4         // line 3
于 2013-10-15T18:38:10.750 に答える