Create a File for use with open().
Create a File with the provided path and style.
Throw an IOException, with the provided message.
Throw an IOException noting the last error.
Exception class thrown on errors.
Throw a potentially reusable IOException, with the provided message, function name and error code.
Return the total length of this file.
Low level open for sub-classes that need to apply specific attributes.
Open a file with the provided style.
Return the current file position.
Set the file seek position to the specified offset from the given anchor.
Wraps the already open file descriptor into a File instance.
Return the Style used for this file.
Instructs the OS to flush it's internal buffers to the disk device.
Return the path used by this file.
Set the file size to be that of the current seek position. The file must be writable for this to succeed.
Set the file size to be the specified length. The file must be writable for this to succeed.
Convenience function to append content to a file.
Convenience function to return the content of a file.
Convenience function to return the content of a file.
Convenience function to set file content and length to reflect the given array.
Read an existing file.
Read an existing file.
Read from the beginning, append at the end of the file.
Read & write on a clean file. Create if necessary.
Read and write an existing file.
Read and Write. Use existing file if present.
Write at the end of the file.
Write on a clean file. Create if necessary.
Write on an existing file. Do not create.
Fits into 32 bits ...
expose superclass definition also
Throw an IOException noting the last error.
Return the name of this device.
Return a preferred size for buffering conduit I/O.
Sets the device in the non-blocking mode.
Allow adjustment of standard IO handles.
Release the underlying file.
Read a chunk of bytes from the file into the provided array
Write a chunk of bytes to the file from the provided array.
Read a chunk of bytes from the file from the given offset, into the provided array
Write a chunk of bytes to the file starting from the given offset, from the provided array
Implements a means of reading and writing a generic file. Conduits are the primary means of accessing external data, and File extends the basic pattern by providing file-specific methods to set the file size, seek to a specific file position and so on.
Serial input and output is straightforward. In this example we copy a file directly to the console:
And here we copy one file to another:
You can use InputStream.load() to load a file directly into memory:
Or use a convenience static function within File:
A more explicit version with a similar result would be:
Conversely, one may write directly to a File like so:
There are equivalent static functions, File.set() and File.append(), which set or append file content respectively.
File can happily handle random I/O. Here we use seek() to relocate the file pointer:
Note that File is unbuffered by default - wrap an instance within ocean.io.stream.Buffered for buffered I/O.
Compile with -version=Win32SansUnicode to enable Win95 & Win32s file support.