File Interface
File objects are references to files.
To operate on the underlying file data you need to either get streams using openInputStream and openOutputStream or open the file for random access operations using open.
Constructors
Code new File.fromPath(Path path) #
Create a File object from a Path object.
File.fromPath(Path path);
Methods
Code Future<File> create() #
Create the file. Returns a Future<File>
that completes with
the file when it has been created.
Existing files are left untouched by create. Calling create on an existing file might fail if there are restrictive permissions on the file.
Future<File> create();
Code void createSync() #
Synchronously create the file. Existing files are left untouched by create. Calling create on an existing file might fail if there are restrictive permissions on the file.
void createSync();
Code Future<File> delete() #
Delete the file. Returns a Future<File>
that completes with
the file when it has been deleted.
Future<File> delete();
Code void deleteSync() #
Synchronously delete the file.
void deleteSync();
Code Future<Directory> directory() #
Get a Directory object for the directory containing this
file. Returns a Future<Directory>
that completes with the
directory.
Future<Directory> directory();
Code Directory directorySync() #
Synchronously get a Directory object for the directory containing this file.
Directory directorySync();
Code Future<bool> exists() #
Check if the file exists. Does not block and returns a
Future<bool>
.
Future<bool> exists();
Code Future<String> fullPath() #
Get the canonical full path corresponding to the file name.
Returns a Future<String>
that completes with the path.
Future<String> fullPath();
Code String fullPathSync() #
Synchronously get the canonical full path corresponding to the file name.
String fullPathSync();
Code Future<Date> lastModified() #
Get the last-modified time of the file. Returns a
Future<Date>
that completes with a Date
object for the
modification date.
Future<Date> lastModified();
Code Date lastModifiedSync() #
Get the last-modified time of the file. Throws an exception if the file does not exist.
Date lastModifiedSync();
Code Future<int> length() #
Get the length of the file. Returns a Future<int>
that
completes with the length in bytes.
Future<int> length();
Code Future<RandomAccessFile> open([FileMode mode]) #
Open the file for random access operations. Returns a
Future<RandomAccessFile>
that completes with the opened
random access file. RandomAccessFiles must be closed using the
close
method.
Files can be opened in three modes:
FileMode.READ: open the file for reading.
FileMode.WRITE: open the file for both reading and writing and truncate the file to length zero. If the file does not exist the file is created.
FileMode.APPEND: same as FileMode.WRITE except that the file is not truncated.
The default value for
mode is FileMode.READ
.
Future<RandomAccessFile> open([FileMode mode]);
Code InputStream openInputStream() #
Create a new independent input stream for the file. The file input stream must be closed when no longer used to free up system resources.
InputStream openInputStream();
Code OutputStream openOutputStream([FileMode mode]) #
Creates a new independent output stream for the file. The file output stream must be closed when no longer used to free up system resources.
An output stream can be opened in two modes:
FileMode.WRITE: create the stream and truncate the underlying file to length zero.
FileMode.APPEND: create the stream and set the position to the end of the underlying file.
By default the mode is FileMode.WRITE.
OutputStream openOutputStream([FileMode mode]);
Code RandomAccessFile openSync([FileMode mode]) #
Synchronously open the file for random access operations. The
result is a RandomAccessFile on which random access operations
can be performed. Opened RandomAccessFiles must be closed using
the close
method.
The default value for
mode is FileMode.READ
.
See open for information on the mode argument.
RandomAccessFile openSync([FileMode mode]);
Code Future<List<int>> readAsBytes() #
Read the entire file contents as a list of bytes. Returns a
Future<List<int>>
that completes with the list of bytes that
is the contents of the file.
Future<List<int>> readAsBytes();
Code List<int> readAsBytesSync() #
Synchronously read the entire file contents as a list of bytes.
List<int> readAsBytesSync();
Code Future<List<String>> readAsLines([Encoding encoding]) #
Read the entire file contents as lines of text using the give
encoding. The default encoding is Encoding.UTF_8
.
Returns a Future<List<String>>
that completes with the lines
once the file contents has been read.
Future<List<String>> readAsLines([Encoding encoding]);
Code List<String> readAsLinesSync([Encoding encoding]) #
Synchronously read the entire file contents as lines of text
using the given
encoding The default encoding is
Encoding.UTF_8
.
List<String> readAsLinesSync([Encoding encoding]);