Arduino File.readStringUntil()


The File.readStringUntil() function reads characters from a file into a String. The function terminates if the terminator character is detected or it times out (see setTimeout()).

The File.readStringUntil() function inherits from the Stream utility class.



Parameter Values

  • file: an instance of a class that inherits from File.
  • terminator: the character to search for. Allowed data types: char.

Return Values

  • The entire String read from a file, up to the terminator character

Notes and Warnings

The terminator character is discarded from the return

Example Code

Create a arduino.txt file with the below content

Hi Arduino
/* * Created by * * This example code is in the public domain * * Tutorial page: */ #include <SD.h> #define PIN_SPI_CS 4 File file; void setup() { Serial.begin(9600); if (!SD.begin(PIN_SPI_CS)) { Serial.println(F("SD CARD FAILED, OR NOT PRESENT!")); while (1); // don't do anything more: } // open file for reading file ="arduino.txt", FILE_READ); if (file) { int line_count = 0; while (file.available()) { String line = file.readStringUntil('\n'); // \n character is discarded from buffer line_count++; Serial.print("Line "); Serial.print(line_count); Serial.print(": "); Serial.println(line); } file.close(); } else { Serial.print(F("SD Card: error on opening file")); } } void loop() { }
  • Open Serial Monitor, you will see as below:
Line 1: Hi Line 2: Arduino
Autoscroll Show timestamp
Clear output
9600 baud  


Arduino UNO R3
Arduino Starter Kit
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.