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.

2
  • 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. Commented Sep 25, 2016 at 5: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. Commented Sep 25, 2016 at 14:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.