public interface FileSystem
SYSTEM implementation, which uses the host machine's local file system. Alternate implementations may be used to inject faults (for testing) or to transform stored data (to add encryption, for example).
All operations on a file system are racy. For example, guarding a call to source(java.io.File) with exists(java.io.File) does not guarantee that FileNotFoundException will not be thrown. The file may be moved between the two calls!
This interface is less ambitious than FileSystem introduced in Java 7. It lacks important features like file watching, metadata, permissions, and disk space information. In exchange for these limitations, this interface is easier to implement and works on all versions of Java and Android.
| Modifier and Type | Field and Description |
|---|---|
static FileSystem |
SYSTEM
The host machine's local file system.
|
| Modifier and Type | Method and Description |
|---|---|
okio |
appendingSink(File
Writes to
file, appending if data is already present.
|
void |
delete(File
Deletes
file if it exists.
|
void |
deleteContents(File
Recursively delete the contents of
directory.
|
boolean |
exists(File
Returns true if
file exists on the file system.
|
void |
rename(File
Renames
from to
to.
|
okio |
sink(File
Writes to
file, discarding any data already present.
|
long |
size(File
Returns the number of bytes stored in
file, or 0 if it does not exist.
|
okio |
source(File
Reads from
file.
|
static final FileSystemSYSTEM
okio.Source source(File file) throws FileNotFoundException
file.
FileNotFoundException
okio.Sink sink(File file) throws FileNotFoundException
file, discarding any data already present. Creates parent directories if necessary.
FileNotFoundException
okio.Sink appendingSink(File file) throws FileNotFoundException
file, appending if data is already present. Creates parent directories if necessary.
FileNotFoundException
void delete(Filefile) throws IOException
file if it exists. Throws if the file exists and cannot be deleted.
IOException
boolean exists(Filefile)
file exists on the file system.
long size(Filefile)
file, or 0 if it does not exist.
void rename(Filefrom, File to) throws IOException
from to
to. Throws if the file cannot be renamed.
IOException
void deleteContents(Filedirectory) throws IOException
directory. Throws an IOException if any file could not be deleted, or if
dir is not a readable directory.
IOException