接口 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.

  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final FileSystem
    The host machine's local file system.
  • 方法概要

    修饰符和类型
    方法
    说明
    Writes to file, appending if data is already present.
    void
    delete(File file)
    Deletes file if it exists.
    void
    deleteContents(File directory)
    Recursively delete the contents of directory.
    boolean
    exists(File file)
    Returns true if file exists on the file system.
    void
    rename(File from, File to)
    Renames from to to.
    sink(File file)
    Writes to file, discarding any data already present.
    long
    size(File file)
    Returns the number of bytes stored in file, or 0 if it does not exist.
    source(File file)
    Reads from file.
  • 字段详细资料

    • SYSTEM

      static final FileSystem SYSTEM
      The host machine's local file system.
  • 方法详细资料