Package org.aoju.bus.core.io
Interface FileSystem
public interface FileSystem
Access to read and write files on a hierarchical data store. Most callers should use the
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.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionappendingSink(File file) Writes tofile, appending if data is already present.voidDeletesfileif it exists.voiddeleteContents(File directory) Recursively delete the contents ofdirectory.booleanReturns true iffileexists on the file system.voidRenamesfromtoto.Writes tofile, discarding any data already present.longReturns the number of bytes stored infile, or 0 if it does not exist.Reads fromfile.
-
Field Details
-
SYSTEM
The host machine's local file system.
-
-
Method Details
-
source
Reads fromfile.- Throws:
FileNotFoundException
-
sink
Writes tofile, discarding any data already present. Creates parent directories if necessary.- Throws:
FileNotFoundException
-
appendingSink
Writes tofile, appending if data is already present. Creates parent directories if necessary.- Throws:
FileNotFoundException
-
delete
Deletesfileif it exists. Throws if the file exists and cannot be deleted.- Throws:
IOException
-
exists
Returns true iffileexists on the file system. -
size
Returns the number of bytes stored infile, or 0 if it does not exist. -
rename
Renamesfromtoto. Throws if the file cannot be renamed.- Throws:
IOException
-
deleteContents
Recursively delete the contents ofdirectory. Throws an IOException if any file could not be deleted, or ifdiris not a readable directory.- Throws:
IOException
-