D2BS
Public Member Functions | Static Public Member Functions | Public Attributes

File Class Reference

This class handles the opening, reading and writing of files. More...

List of all members.

Public Member Functions

File close ()
 Close the current file and then return it.
File reopen ()
 Reopen the file, equivalent to calling open with the same parameters as were used the first time.
String read (int count)
 Read count chars from the file.
byte[] read (int count)
 Read count bytes from the file.
String readLine ()
 Read a line from the file and return it.
String[] readAllLines ()
 Read all the lines from the file into a String array.
String readAll ()
 Read the entire file and return as a String.
File write (...)
 Write the string representation (for standard files) or the binary representation (for binary files) of each of the arguments to the File.
File seek (int n)
 Seek n bytes from the current location.
File seek (int n, bool isLines, bool fromStart=false)
 Seek n bytes or lines (depending on isLines) from the current location or the start of file (depending on fromStart).
File flush ()
 Flush the buffers for the File.
File reset ()
 Seek back to the beginning of the File.
File end ()
 Seek to the end of the File.

Static Public Member Functions

static File open (String file, int mode)
 Open a file with the given settings.
static File open (String file, int mode, bool binary=false, bool autoflush=false, bool lockFile=false)
 Open a file with the given settings.

Public Attributes

bool readable
 Whether or not the file can be read from.
bool writeable
 Whether or not the file is writeable.
bool seekable
 Whether or not the file is seekable.
int mode
 The mode the file was opened with.
bool binaryMode
 Whether the file was opened as a binary file or not.
int length
 The file length.
String path
 The relative path to the File (the filename/path given for opening).
int position
 The position in the File (where the next read or write will occur).
bool eof
 Whether or not the File is at end of file.
int accessed
 The last accessed time of the File.
int created
 The creation time of the File.
int modified
 The last modified time of the File.
bool autoflush
 Whether or not to autoflush the File.

Detailed Description

This class handles the opening, reading and writing of files.


Member Function Documentation

File File::close ( )

Close the current file and then return it.

Returns:
The same File object.
File File::end ( )

Seek to the end of the File.

Returns:
The File.
File File::flush ( )

Flush the buffers for the File.

Returns:
The File.
static File File::open ( String  file,
int  mode,
bool  binary = false,
bool  autoflush = false,
bool  lockFile = false 
) [static]

Open a file with the given settings.

Parameters:
fileThe filename.
modeThe mode of the file (read/write/append). Use FILE_READ, FILE_WRITE and FILE_APPEND. FILE_READ corresponds to a C mode of "r". FILE_WRITE corresponds to a C mode of "w+". FILE_APPEND corresponds to a C mode of "a+".
binaryWhether to open the file in text or binary mode. If opening in text mode a "t" is appended to the C mode, otherwise a "b" is appended.
autoflushWhether to flush after each write.
lockFileWhether or not to lock the file.
Returns:
The File object just created.
static File File::open ( String  file,
int  mode 
) [static]

Open a file with the given settings.

Uses defaults: binary = false, autoflush = false, lockFile = false.

Parameters:
fileThe filename.
modeThe mode of the file (read/write/append). Use FILE_READ, FILE_WRITE and FILE_APPEND. FILE_READ corresponds to a C mode of "r". FILE_WRITE corresponds to a C mode of "w+". FILE_APPEND corresponds to a C mode of "a+".
Returns:
The File object just created.
byte [] File::read ( int  count)

Read count bytes from the file.

Used when the file was opened in binary mode.

Parameters:
countThe number of bytes to read.
Returns:
An array of the bytes read.
String File::read ( int  count)

Read count chars from the file.

Used when the file was not opened in binary mode.

Parameters:
countThe number of characters to read.
Returns:
The characters that were read.
String File::readAll ( )

Read the entire file and return as a String.

Includes a seek to start from the beginning of the file, regardless of where the current position was.

Returns:
The entire file in a String.
String [] File::readAllLines ( )

Read all the lines from the file into a String array.

Returns:
An array of all the lines in the file.
String File::readLine ( )

Read a line from the file and return it.

Returns:
The line.
File File::reopen ( )

Reopen the file, equivalent to calling open with the same parameters as were used the first time.

Returns:
The same File object.
File File::reset ( )

Seek back to the beginning of the File.

Returns:
The File.
File File::seek ( int  n,
bool  isLines,
bool  fromStart = false 
)

Seek n bytes or lines (depending on isLines) from the current location or the start of file (depending on fromStart).

Parameters:
nNumber of bytes or lines to move.
isLinesWhether n is a number of lines, or just bytes.
fromStartWhether to start from the start of file, or the current location.
Returns:
The File.
File File::seek ( int  n)

Seek n bytes from the current location.

Parameters:
nNumber of bytes to move..
Returns:
The File.
File File::write (   ...)

Write the string representation (for standard files) or the binary representation (for binary files) of each of the arguments to the File.

Returns:
The File.

Member Data Documentation

The mode the file was opened with.

Compare with FILE_READ, FILE_WRITE and FILE_APPEND.

Whether or not the file can be read from.

Based on whether the File is open, whether it is at the end of file, and whether there is an error pending.

Whether or not the file is seekable.

Based on whether the File is open and whether there is an error pending.

Whether or not the file is writeable.

Based on whether the File is open, whether there is an error pending and whether the File was opened for writing or not.