使用 OpenCSV 从 csv 读取流数据
Read streaming data from csv using OpenCSV
我有加速度计和陀螺仪传感器流数据,这些数据保存在下载文件夹中。
我想实时读取所有数据或逐行读取数据流,但我无法超越第一行。
try {
CSVReader reader = newCSVReader(newFileReader(path.getAbsoluteFile()));
{
List<String[]>allRows = reader.readAll();
for (String[]row :allRows)
Log.i(TAG1,Arrays.toString(row));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
在输出中只打印第一行。
我需要阅读每一行,以便我可以做进一步的操作。
Int 文档显示了两种不同的方法:
1- 迭代器样式模式:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null)
{
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
2- 有一个列表:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List<String[]> myEntries = reader.readAll();
for(String[] item : myEntries)
System.out.println(item);
因此,如果这些示例中的任何一个向您显示多行,请检查您的文件是否只包含一行,也许您正在将文件中的所有数据都写在第一行或类似的地方。
我有加速度计和陀螺仪传感器流数据,这些数据保存在下载文件夹中。 我想实时读取所有数据或逐行读取数据流,但我无法超越第一行。
try {
CSVReader reader = newCSVReader(newFileReader(path.getAbsoluteFile()));
{
List<String[]>allRows = reader.readAll();
for (String[]row :allRows)
Log.i(TAG1,Arrays.toString(row));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
在输出中只打印第一行。 我需要阅读每一行,以便我可以做进一步的操作。
Int 文档显示了两种不同的方法:
1- 迭代器样式模式:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null)
{
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
2- 有一个列表:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List<String[]> myEntries = reader.readAll();
for(String[] item : myEntries)
System.out.println(item);
因此,如果这些示例中的任何一个向您显示多行,请检查您的文件是否只包含一行,也许您正在将文件中的所有数据都写在第一行或类似的地方。