Go Down

Topic: load one line at a time from txt (Read 1 time) previous topic - next topic

84billy

I have this code, which loads the contents of a txt composed of 6 lines

Code: [Select]
  String path="/mnt/sd/Arduino/www/Innaffiaduino/txt/prog_" + valorezon + i +".txt";
  File dataFiles = FileSystem.open(path.c_str());
  valorezona="";
  while (dataFiles.available()) {
        valorezona=valorezona + (char)dataFiles.read();
        Console.println("ciclo");
                                  }


how can I modify it to load one line at a time or to understand when they are at end of line?

VideoLiam

Hi,

Try compairing each character you read to the Hex value 'D' or the Oct '015' which are the Ascii values for carage return. Or if the file is delimited some other way a comma for example compair to that.

Try googling 'Ascii'

Regards

Liam

dreggy

Quote

  String path="/mnt/sd/Arduino/www/Innaffiaduino/txt/prog_" + valorezon + i +".txt";
  File dataFiles = FileSystem.open(path.c_str());
  valorezona="";
  byte c;
  String valore = "";
  while ( (c = script.read()) >= 0 ) //read one byte at time
  {
     if ( c == 13 ){ // check for newline
       // here you can exit from cycle or use the value
       Console.println("ciclo");
       valore = "";
     }else
        valore .concat( (char) c );
  }




federicofissore

#3
Sep 30, 2013, 09:29 am Last Edit: Sep 30, 2013, 09:32 am by Federico Fissore Reason: 1
As File inherits from Stream, you can use readStringUntil('\n')

Go Up