fs

The object provides methods to read and write files. All methods are asynchronous and return a promise.

Import this object with “”

Parameters:

Reads the contents of a given directory. Returns a promise that resolves on success to an array of the names of the files in the directory excluding ‘.’ and ‘..’. In case of failure, the Promise rejects with an Error.

readFile(path)

Parameters:

  • path: string
    • the path of the file to read.
      Returns: Promise

Reads the given file and returns a promise that resolves to the contents of the file on success and rejects with an Error in case of a failure. The file contents are returned as an ArrayBuffer.

  • path: string
    • the path of the file to read.

Reads the given text file and returns a promise that resolves to the contents of the file on success and rejects with an Error in case of a failure. The file contents are returned as a string.

removeFile(path)

Parameters:

  • path: string
    • the path of the file to remove.
      Returns: Promise

Removes the given file. Returns a promise that resolves on success and rejects with an Error in case of a failure.

Parameters:

  • path: string
    • the path of the file to write.

Writes the given binary contents to the given file. If the file exists, it is overwritten, otherwise it is created. Returns a promise that resolves on success and rejects with an Error in case of a failure.

writeFile(path, text, encoding)

Parameters:

  • path: string
    • the path of the file to write.
  • text: string
    • the text to write to the file.

read-only Type: string

The path of a directory that the app may use to store cached files. The OS may delete files in this directory when the device runs low on storage. Only use this location for data that can easily be re-created.This property can only be set on widget creation. Once set, it cannot be changed anymore.

filesDir

read-only Type: string

The path of a directory that the app may use to store persistent files.This property can only be set on widget creation. Once set, it cannot be changed anymore.

原文: