openCSV を使用して csv の一部の行を取得して表示する方法。私は現在、次のコードを持っています:
CSVReader reader1 = new CSVReader(new FileReader(mydata_csv.getpath()));
List myDatas = reader1.readAll();
特定の1行を表示するには?
データを保存するためのより良い方法を使用できるかもしれません (csv には数百行の変数が含まれています)。どんな提案も大歓迎です。
opencsv http://opencsv.sourceforge.net/#how-to-readのドキュメントには、コードが String[] のリストを返すと書かれているようです。
その場合、私は次のように書きます:
CSVReader reader1 = new CSVReader(new FileReader(mydata_csv.getpath()));
List<String[]> myDatas = reader1.readAll();
String[] lineI = myDatas.get(i);
for (String[] line : myDatas) {
for (String value : line) {
//do stuff with value
}
}
次のコードを使用する必要があります。
CSVReader reader = new CSVReader(new FileReader(mydata_csv.getpath()));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}