ASL
|
Class TextFile represents a text file in the filesystem.
It can be used to get information about a file (its size, its modification date, whether it exists), to read or write in it in one step, or to open it and perform typical read/write operations as text, just like File
.
Functions text(),
lines(),
write(),
append(),
printf()`, etc. read or write in the file by first opening it. Intended as a short-hand for one-line operations.
Explicit opening allows reading or writing in an stdio
conventional style:
#include <TextFile.h>
Public Member Functions | |
bool | printf (const char *fmt,...) ASL_PRINTF_W2(2) |
Prints formatted text as with the regular printf. More... | |
int | scanf (const String &fmt, void *p1, void *p2=0, void *p3=0, void *p4=0) |
Reads formatted text as with the regular scanf up to 4 items only! | |
String | readLine () |
Reads and returns a line from the file. | |
String | text () |
Returns the textual content of the file as a string. More... | |
Array< String > | lines () |
Returns all the lines contained in the file as an array of strings. More... | |
bool | append (const String &line) |
Writes the given string at the end of the file, opening in append mode if the file was not opened. More... | |
bool | write (const String &s) |
Writes the given string at the end of the file, opening in write mode if the file was not opened. More... | |
bool | put (const String &s) |
Writes the given string at the end of the file, opening in write mode if the file was not opened. More... | |
Public Member Functions inherited from File | |
File () | |
Constructs a File object with no associated file. | |
File (const String &name) | |
Constructs a File object with the given path name but does not open it. | |
File (const String &name, OpenMode mode) | |
Constructs a File object with the given path name and opens it with the given access mode. More... | |
operator bool () const | |
Returns true if this object refers to an open file. | |
bool | operator== (const File &f) const |
Returns true if this object does not refer to an open file. | |
Date | lastModified () const |
Returns the file's last modification date. | |
Date | creationDate () const |
Returns the file's creation date. | |
bool | setLastModified (const Date &t) |
Sets the file's last modification date. | |
Long | size () const |
Returns the file size. | |
String | name () const |
Returns the file's name (without its directory) | |
String | extension () const |
Returns the file's extension (what follows the last dot) | |
bool | hasExtension (const String &exts) const |
Returns true if this file's extension is any of those given (separated by '|'), case-insensitively. | |
const String & | path () const |
Returns the full path of the file. | |
String | directory () const |
Returns the directory containing the file. | |
bool | isDirectory () const |
Returns true if the 'file' path is a directory. | |
bool | exists () const |
Returns true if the 'file' path exists (file or directory) | |
bool | isFile () const |
Returns true if the 'file' path exists and is actually a file. | |
bool | copy (const String &to) |
Copies this file to a new directory or name. | |
bool | move (const String &to) |
Moves or renames this file to to which can be a full name or a destination directory. | |
bool | remove () |
Deletes the file. | |
ByteArray | firstBytes (int n) |
Returns the first n bytes in the file. | |
ByteArray | content () |
Returns the binary content of the file as an array of bytes. | |
bool | put (const ByteArray &data) |
Writes the binary content of the file from an array of bytes. More... | |
bool | open (const String &name, OpenMode mode=READ) |
Opens the file with the specified access mode. | |
bool | open (OpenMode mode=READ) |
Opens the file with the specified access mode. | |
void | close () |
Closes the file. | |
Long | position () |
Returns the current position in the file. | |
void | seek (Long offset, SeekMode from=START) |
Moves the file pointer to the given position. More... | |
bool | end () |
Returns true if the file pointer reached the end of the file. | |
void | flush () |
Flushes the write buffers effectively writing data on disk. | |
int | read (void *p, int n) |
Reads n bytes from the file into the buffer pointed to by p. | |
int | write (const void *p, int n) |
Writes n bytes from the buffer pointed to by p into the file. | |
template<class T > | |
File & | operator<< (const T &x) |
Writes variable x to the file respecting endianness in binary form. | |
template<class T > | |
File & | operator>> (T &x) |
Reads variable x from the file respecting endianness in binary form. | |
Additional Inherited Members | |
Static Public Member Functions inherited from File | |
static File | temp (const String &ext=".tmp") |
Creates a temporary file with optional extension and returns its path. | |
bool append | ( | const String & | line | ) |
Writes the given string at the end of the file, opening in append mode if the file was not opened.
Returns false on failure.
Returns all the lines contained in the file as an array of strings.
The file does not need to be opened.
bool printf | ( | const char * | fmt, |
... | |||
) |
Prints formatted text as with the regular printf.
Returns false on failure
|
inline |
Writes the given string at the end of the file, opening in write mode if the file was not opened.
Returns false on failure.
String text | ( | ) |
Returns the textual content of the file as a string.
The file does not need to be opened.
bool write | ( | const String & | s | ) |
Writes the given string at the end of the file, opening in write mode if the file was not opened.
Returns false on failure.