|
ASL
|
Class File represents a 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, without explicitly opening it, or to read and write in a more conventional way. The file is automatically closed on object destruction. For text files you should use class TextFile.
There are also conventional functions to explicitly open a file for reading or writing:
File(name, mode) or File::open(name, mode) now support additional flag that fails if the file exists (only where the OS runtime library supports the "x" fopen flag):
#include <File.h>
Inherited by TextFile.
Public Member Functions | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
Static Public Member Functions | |
| static File | temp (const String &ext=".tmp") |
| Creates a temporary file with optional extension and returns its path. | |
Writes the binary content of the file from an array of bytes.
Returns false on failure
Moves the file pointer to the given position.
| offset | new offset position in file |
| from | from where the offset is expressed: START (beginning of file), HERE (current position), END (file end) |