Developer World
Spresense Arduino Library v2.2.0-1e6eb73
File Class Reference

The File class allows for reading from and writing to individual files on the File System. More...

#include <File.h>

Inheritance diagram for File:
Collaboration diagram for File:

Public Member Functions

 File (const char *name, uint8_t mode=FILE_READ)
 Construct a new File object. More...
 
 File ()
 Construct a new File object.
 
 ~File ()
 Destroy File object.
 
virtual size_t write (uint8_t data)
 Write data to the file. More...
 
virtual size_t write (const uint8_t *buf, size_t size)
 Write data to the file. More...
 
virtual int read ()
 Read from the file. More...
 
virtual int peek ()
 Read a byte from the file without advancing to the next one. More...
 
virtual int available ()
 Check if there are any bytes available for reading from the file. More...
 
virtual void flush ()
 Ensures that any bytes written to the file are physically saved to the File System. More...
 
int read (void *buf, size_t nbyte)
 Read from the file. More...
 
boolean seek (uint32_t pos)
 Seek to a new position in the file. More...
 
uint32_t position ()
 Get the current position within the file. More...
 
uint32_t size ()
 Get the size of the file. More...
 
void close ()
 Close the file. More...
 
 operator bool ()
 Check if the file or directory exists.
 
char * name ()
 Returns the file name. More...
 
boolean isDirectory (void)
 Check if the current file is a directory or not. More...
 
File openNextFile (uint8_t mode=O_RDONLY)
 Reports the next file or folder in a directory. More...
 
void rewindDirectory (void)
 Bring you back to the first file in the directory.
 

Detailed Description

The File class allows for reading from and writing to individual files on the File System.

Constructor & Destructor Documentation

◆ File()

File::File ( const char *  name,
uint8_t  mode = FILE_READ 
)

Construct a new File object.

Parameters
[in]nameThe name of the file
[in]modeThe mode of the file

Member Function Documentation

◆ write() [1/2]

virtual size_t File::write ( uint8_t  data)
virtual

Write data to the file.

Parameters
[in]dataThe byte to write.
Returns
The number of bytes written.

◆ write() [2/2]

virtual size_t File::write ( const uint8_t *  buf,
size_t  size 
)
virtual

Write data to the file.

Parameters
[in]bufArray of bytes.
[in]sizeThe number of elements in buf.
Returns
The number of bytes written.

◆ read() [1/2]

virtual int File::read ( )
virtual

Read from the file.

Returns
The next byte, or -1 if none is available.

◆ peek()

virtual int File::peek ( )
virtual

Read a byte from the file without advancing to the next one.

Returns
The next byte, or -1 if none is available.

◆ available()

virtual int File::available ( )
virtual

Check if there are any bytes available for reading from the file.

Returns
the number of bytes available

◆ flush()

virtual void File::flush ( )
virtual

Ensures that any bytes written to the file are physically saved to the File System.

This is done automatically when the file is closed.

◆ read() [2/2]

int File::read ( void *  buf,
size_t  nbyte 
)

Read from the file.

Parameters
[out]bufArray of bytes.
[in]nbyteThe number of elements in buf.
Returns
The total number of bytes successfully read, or -1 if none is available

◆ seek()

boolean File::seek ( uint32_t  pos)

Seek to a new position in the file.

Parameters
[in]posThe position to which to seek.
Returns
true for success, false for failure

◆ position()

uint32_t File::position ( )

Get the current position within the file.

Returns
the position within the file

◆ size()

uint32_t File::size ( )

Get the size of the file.

Returns
the size of the file in bytes

◆ close()

void File::close ( )

Close the file.

Ensure that any data written to it is physically saved to the File System.

◆ name()

char* File::name ( )

Returns the file name.

Returns
the file name

◆ isDirectory()

boolean File::isDirectory ( void  )

Check if the current file is a directory or not.

Returns
true if is a directory, false if not

◆ openNextFile()

File File::openNextFile ( uint8_t  mode = O_RDONLY)

Reports the next file or folder in a directory.

Parameters
[in]modeThe mode in which to open the next file.
Returns
The next file or folder in the path

The documentation for this class was generated from the following file: