Hardware Reference
In-Depth Information
To know if there are any more bytes available for reading, use
available()
.
number = file.available();
This function returns the remaining bytes inside a i le, as an
int
.
Writing Files
Three functions are used to write data to a i le.
print()
and
println()
are used
in the same way as the Serial functions of the same name and
write()
places
bytes at the pointer position in the i le.
print()
and
println()
can be used to write formatted data: text and decimal
numbers, as well as binary, hexadecimal, and octal representations using the
optional
base
parameter. By specifying
BIN
as the base parameter,
print
will
write binary notation. Using
OCT
and
HEX
,
print
will write octal and hexadecimal
respectively. The difference between
print()
and
println()
is that
println()
automatically adds a new line character at the end. Both of these functions
ignore the i le pointer and append data to the end of the i le.
file.print(data);
file.print(data, base);
file.println(data);
file.println(data, base);
The
write()
function is different. It can write data directly inside a i le but
will not insert data; it will overwrite any data present if not at the end of the i le.
file.write(data);
file.write(buffer, len);
The
data
parameter can be a
byte
, a
char
, or a
string
. The
buffer
param-
eter is a
byte
, array of
char
, or a
String
, and the
len
parameter indicates the
number of bytes to be used.
write()
,
print()
, and
println()
also return the number of bytes written to
the buffer, but reading this is optional.
Folder Operations
If no directory is specii ed, all operations are performed on the root folder of the
SD card. It is, however, possible to create folders and work inside those folders.
Folders are used in the UNIX fashion; paths are separated by forward slashes
( / ), for example, folder/i le.txt. All folders are named from the root folder; you
cannot "cd" into a folder without i rst specifying the root folder(s).
Search WWH ::
Custom Search