我有加速度计和陀螺仪传感器流数据,保存在下载文件夹中。
我想实时读取所有数据或逐行读取数据流,但我无法超出第一行。
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);
因此,如果这些示例中的任何一个显示多于一行,请检查您的文件是否只包含一行,也许您正在将文件中的所有数据全部写入第一行或类似的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)