Arduino File.readBytesUntil()
Description
The File.readBytesUntil() function reads characters from a file into a buffer. The function terminates if the terminator character is detected, the determined length has been read, or it times out (see setTimeout()). The function returns the characters up to the last character before the supplied terminator. The terminator itself is not returned in the buffer.
The File.readBytesUntil() function returns the number of bytes placed in the buffer. A 0 means no valid data was found.
The File.readBytesUntil() function inherits from the Stream utility class.
Syntax
file.readBytesUntil(character, buffer, length)
Parameter Values
- file: an instance of a class that inherits from File.
- character: the character to search for. Allowed data types: char.
- buffer: the buffer to store the bytes in. Allowed data types: array of char or byte.
- length: the number of bytes to read. Allowed data types: int.
Return Values
- The number of bytes placed in the buffer.
Notes and Warnings
The terminator character is discarded from the return
Example Code
- Connect the SD Card to your your PC via an USB 3.0 SD Card Reader
Create a arduino.txt file with the below content
- Connect SD Card to Arduino. See Arduino - Micro SD Card tutorial
- Upload below code to Arduino via Arduino IDE
- Open Serial Monitor, you will see as below:
Tutorials
See Also
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Additionally, some links direct to products from our own brand, DIYables.