Create a File for use with open().
Create a File with the provided path and style.
Low level open for sub-classes that need to apply specific attributes.
Open a file with the provided style.
Low level open for sub-classes that need to apply specific attributes.
Open a file with the provided style.
Set the file seek position to the specified offset from the given anchor.
Set the file seek position to the specified offset from the given anchor.
Instructs the OS to flush it's internal buffers to the disk device.
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.
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.
Return the total length of this file.
Return the total length of this file.
Return the current file position.
Return the current file position.
Return the Style used for this file.
Convenience function to append content to a file.
Convenience function to return the content of a file. Returns a slice of the provided output buffer, where that has sufficient capacity, and allocates from the heap where the file content is larger.
Convenience function to set file content and length to reflect the given array.
Fits into 32 bits ...
Read an existing file.
Read an existing 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.
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.
Windows-specific code.
Windows-specific code.
Allow adjustment of standard IO handles.
Return the underlying OS handle of this Conduit.
Release the underlying file. Note that an exception is not thrown on error, as doing so can induce some spaggetti into error handling. Instead, we need to change this to return a bool instead, so the caller can decide what to do.
Read a chunk of bytes from the file into the provided array. Returns the number of bytes read, or Eof where there is no further data.
Write a chunk of bytes to the file from the provided array. Returns the number of bytes written, or Eof if the output is no longer available.
Unix-specific code.
Allow adjustment of standard IO handles.
Return the underlying OS handle of this Conduit.
Release the underlying file.
Read a chunk of bytes from the file into the provided array. Returns the number of bytes read, or Eof where there is no further data.
Write a chunk of bytes to the file from the provided array. Returns the number of bytes written, or Eof if the output is no longer available.
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 tango.io.stream.Buffered for buffered I/O.
Compile with -version=Win32SansUnicode to enable Win95 & Win32s file support.