title: From .txt file in sd card to string variable in Arduino
body: <p>I'm trying to read a text file in an Arduino SD card reader and copy its text into a string variable, but the function .read always returns -1. How can I solve this problem?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;SPI.h&gt;
  #include &lt;SD.h&gt;
  
  File mappa;
  String text;
  
  void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  mappa = SD.open("map.txt");
  
  // if the file opened okay, write to it:
  if (mappa) {
    Serial.println("File aperto");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening map.txt");
  }
  Serial.println("map.txt:");
  
  // read from the file until there's nothing else in it:
  while (mappa.available()) {
    Serial.write(mappa.read());
   // text = parseInt(mappa.read());
  }
  Serial.println(text);
    // close the file:
    mappa.close();  
  }
  void loop() {
    // nothing happens after setup
  }
  </code></pre>
  
  <p>I know that <code>.read()</code> returns an array of integers, but I don't know how to access them separately.</p>