2

I have Accelerometer and Gyro sensor streaming data which is saved in Download folder. I want to read all the data or line by line as the data stream in real time,but i am not able to go beyond first line.

 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();
     }

in the output only first line is printed. I need to read each line so that i can do further operation.

AlphabateCoder
  • 95
  • 2
  • 11
  • What version of openCSV are you using? There was a known issue with reading from Streams in versions 3.0-3.4 . Please update to version 3.8 and give it a try. – Scott Conway Sep 25 '16 at 05:33
  • @PeterSmith i am using 3.8 version of Opencsv. Actually i am trying to read stream data in real time, for that i will have to use threading. – AlphabateCoder Sep 25 '16 at 14:59

1 Answers1

1

Int the documentation shows two different ways to do it:

1- Iterator style pattern:

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- With a List:

CSVReader reader = new CSVReader(new FileReader("yourfile.csv")); 
List<String[]> myEntries = reader.readAll(); 

for(String[] item : myEntries)
    System.out.println(item);

So, if any of these example shows you more than one line, check if your file contains just one line, maybe you are writing all your data in the file all in the first line or something like that.

Pau
  • 14,917
  • 14
  • 67
  • 94
  • I tried both ways, still not more that first line is printed.There are thousands of rows as the data is streaming 50 rows per second. – AlphabateCoder Sep 24 '16 at 09:29
  • now i am able to read data, actually earlier i put the above code before the execution of the file. Still partial data is read, want to read data in realtime as streaming happens. – AlphabateCoder Sep 24 '16 at 14:07