Appearance
File 
saveFile 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
saveFile(Object object)
Save the file locally. Note:saveFile Will move the temporary file, so the tempFilePath Will not be available
Note
saveFile will move the temporary file, so the tempFilePath passed in will not be available after a successful call.
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| tempFilePath | string | yes | Temporary path to the file you want to save (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| savedFilePath | string | File path after storage (Local path) | 
sample code
javascript
ft.chooseImage({
  success(res) {
    const tempFilePaths = res.tempFilePaths
    ft.saveFile({
      tempFilePath: tempFilePaths[0],
      success(res) {
        const savedFilePath = res.savedFilePath
      }
    })
  }
}):: tip Note The size limit for local file storage is 10M :::
removeSavedFile 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
removeSavedFile(Object object)
Delete local cache file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| tempFilePath | string | yes | File path to delete (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
sample code
javascript
ft.getSavedFileList({
  success(res) {
    if (res.fileList.length > 0) {
      ft.removeSavedFile({
        filePath: res.fileList[0].filePath,
        complete(res) {
          console.log(res)
        }
      })
    }
  }
})openDocument 
Supported since base library 1.3.9, iOS version 2.1.23, Android not yet supported
openDocument(Object object)
A new page opens the document. WeChat Client 7.0.12 Version of the default display of the upper right corner menu on, after the default version does not show, you need to take the initiative to pass showMenu。
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path (Local path) , through downloadFile Get | |
| fileType | string | no | Whether to show the top right menu | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fileType Legal value
| value | Introductions | 
|---|---|
| doc | doc format | 
| docx | docx format | 
| xls | xls format | 
| xlsx | xlsx format | 
| ppt | ppt format | 
| pptx | pptx format | 
| pdf format | 
sample code
javascript
ft.downloadFile({
  // Example Url, not real
  url: 'http://example.com/somefile.pdf',
  success(res) {
    const filePath = res.tempFilePath
    ft.openDocument({
      filePath,
      success(res) {
        console.log('Document opened successfully.')
      }
    })
  }
})getSavedFileList 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
getSavedFileList(Object object)
Gets a list of local cache files saved under the Mini Program
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| fileList | Array.<Object> | Array of files, each one a FileItem | 
res.fileList Structure
| attribute | type | Introductions | 
|---|---|---|
| filePath | string | File path (Local path) | 
| size | number | Local file size in bytes | 
| createTime | number | Time stamp when file is saved, from 1970/01/01 08:00:00 Number of seconds to the current time | 
sample code
javascript
ft.getSavedFileList({
  success(res) {
    console.log(res.fileList)
  }
})getSavedFileInfo 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
getSavedFileInfo(Object object)
Gets the file information for the local file. This interface can only be used to obtain files that have been saved locally. To obtain temporary file information, use ft.getFileInfo() Interface.
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| size | number | File size, unit B | 
| createTime | number | Time stamp when file is saved, from 1970/01/01 08:00:00 Number of seconds to the time | 
sample code
javascript
ft.getSavedFileList({
  success(res) {
    console.log(res.fileList)
  }
})getFileInfo 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
getFileInfo(Object object)
Get File Information
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | Local file path | |
| digestAlgorithm | string | 'md5' | no | Algorithm for computing file summaries | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.digestAlgorithm Legal value
| value | Introductions | 
|---|---|
| md5 | md5 algorithm | 
| sha1 | sha1 algorithm | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| size | number | File size, in bytes | 
| digest | string | According to the incoming digestAlgorithm Summary of calculated documents | 
sample code
javascript
ft.getFileInfo({
  success(res) {
    console.log(res.size)
    console.log(res.digest)
  }
})saveFileToDisk 
Save file system files to the user disk, only in the PC End support
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | Path of the file to be saved | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
sample code
javascript
ft.saveFileToDisk({
  filePath: `${ft.env.USER_DATA_PATH}/hello.txt`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})getFileSystemManager 
Foundation Library 2.10.6 support from
getFileSystemManager()
Get the globally unique file manager
Return value
FileSystemManager
ile manager, available through the ft.getFileSystemManager Get.
FileSystemManager.access 
FileSystemManager.access(Object object)
Judgment file/Directory exists
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| path | string | yes | Files to determine if they exist/Directory path (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
// Judgment file/Directory exists
fs.access({
  path: `${ft.env.USER_DATA_PATH}/hello.txt`, 
  success(res) {
    // File existence
    console.log(res)
  },
  fail(res) {
    // File does not exist or other error
    console.error(res)
  }
})
// Synchronous interface
try {
  fs.accessSync(`${ft.env.USER_DATA_PATH}/hello.txt`)
} catch(and) {
  console.error(and)
}FileSystemManager.accessSync 
FileSystemManager.accessSync(string path)
FileSystemManager.accessThe synchronous version of
parameter
string path
Files to determine if they exist/Directory path (Local path)
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  fs.accessSync(`${ft.env.USER_DATA_PATH}/test.txt`)
} catch(e) {
  console.error(e)
}FileSystemManager.appendFile 
FileSystemManager.appendFile(Object object)
在文件结尾追加内容
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to read (Local path) | |
| data | string/ArrayBuffer | yes | Text or binary data to be appended | |
| encoding | string | utf-8 | no | Specifies the character encoding for writing to the file | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.appendFile({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  data: 'this is text',
  encoding: 'utf-8',
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.appendFileSync 
FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding)
FileSystemManager.appendFileThe synchronised version of
parameter
string filePath
File path to append content (Local path)
string|ArrayBuffer data
Text or binary data to append
string encoding
Specifies the character encoding for writing to the file
sample code
javascript
// Synchronous interface
const fs = ft.getFileSystemManager()
try {
  fs.appendFileSync(`${ft.env.USER_DATA_PATH}/test.txt`, 'this is text', 'utf8')
} catch(e) {
  console.error(e)
}FileSystemManager.close 
FileSystemManager.close(Object object)
Close file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
// Open the file
fs.open({
  filePath: `${ft.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+',
  success(res) {
    // Close file
    fs.close({
      fd: res.fd
    })
  }
})FileSystemManager.closeSync 
FileSystemManager.closeSync(Object object)
Synchronize Close Files
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | 
sample code
javascript
const fs = ft.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+'
})
// Close file
fs.closeSync({ fd: fd })FileSystemManager.copyFile 
FileSystemManager.copyFile(Object object)
Copy file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| srcPath | string | yes | Source file path, support local path | |
| destPath | string | yes | Destination file path, local path support | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.copyFile({
  srcPath: `${ft.env.USER_DATA_PATH}/test-txt`,
  destPath: `${ft.env.USER_DATA_PATH}/new-test.txt`
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.copyFileSync 
FileSystemManager.copyFileSync(string srcPath, string destPath)
FileSystemManager.copyFileThe synchronised version of
parameter
string srcPath
Source file path, support local path
string destPath
Destination file path, local path support
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  fs.copyFileSync(
    `${ft.env.USER_DATA_PATH}/test.txt`,
    `${ft.env.USER_DATA_PATH}/new-test.txt`
  )
} catch(e) {
  console.error(e)
}FileSystemManager.fstat 
FileSystemManager.fstat(Object object)
Get status information for files
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| stats | object | Stats Object that contains the state of the file | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
// Open the file
fs.open({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+',
  success(res) {
    // Get status information for files
    fs.fstat({
      fd: res.fd,
      success(res) {
        console.log(res.stats)
      }
    })
  }
})FileSystemManager.fstatSync 
FileSystemManager.fstatSync(Object object)
Synchronize access to file status information
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | 
Return value
Object object
Stats Object that contains the state of the file
sample code
javascript
const fs = ft.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+'
})
const stats = fs.fstatSync({fd: fd})
console.log(stats)FileSystemManager.ftruncate 
FileSystemManager.ftruncate(Object object)
Truncate file contents
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| length | number | yes | Truncate position, default 0. if length Is less than the file length in bytes, only the first length Four bytes will remain in the file and the rest will be deletedif length Is greater than the file length, it will be expanded, and the extension will be filled with empty bytes0') | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
// Open the file
fs.open({
  filePath: `${ft.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+',
  success(res) {
    // Truncate file contents
    fs.ftruncate({
      fd: res.fd,
      length: 10, // Truncate the file from the 10th byte
      success(res) {
        console.log(res)
      }
    })
  }
})FileSystemManager.ftruncateSync 
FileSystemManager.ftruncateSync(Object object)
Truncate file contents
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| length | number | yes | Truncate position, default 0. if length Is less than the file length in bytes, only the first length Four bytes will remain in the file and the rest will be deletedif length Is greater than the file length, it will be expanded, and the extension will be filled with empty bytes0') | 
Return value
undefined
sample code
javascript
const fs = ft.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+'
})
fs.ftruncateSync({
  fd: fd,
  length: 10 // Truncate the file from the 10th byte
})FileSystemManager.getFileInfo 
FileSystemManager.getFileInfo(Object object)
Under the Mini Program Local temporary file or Local cache file information
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to read (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| size | number | File size, in bytes | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.getFileInfo({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.getSavedFileList 
FileSystemManager.getSavedFileList(Object object)
Gets a list of local cache files saved under the Mini Program
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| fileList | Array.<Object> | File array | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.getSavedFileList({
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.mkdir 
FileSystemManager.mkdir(Object object)
Create a directory
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| dirPath | string | yes | Directory path created (Local path) | |
| recursive | boolean | false | no | Whether to create this directory after recursively creating its parent directory. If the corresponding parent directory already exists, the parent directory is not created. Such as dirPath for a/b/c/d and recursive for True, will create the a Directory, and then in the a Create under directory b Directory, and so on until the a/b/c Directory d Directory. | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.mkdir({
  dirPath: `${ft.env.USER_DATA_PATH}/a/b/c`,
  recursive: false
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.mkdirSync 
FileSystemManager.mkdirSync(string dirPath, boolean recursive)
FileSystemManager.mkdirSyncThe synchronised version of
parameter
string dirPath
Directory path created (Local path)
boolean recursive
Whether to create this directory after recursively creating its parent directory. If the corresponding parent directory already exists, the parent directory is not created. Such as dirPath for a/b/c/d and recursive for True, will create the a Directory, and then in the a Create under directory b Directory, and so on until the a/b/c Directory d Directory
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  fs.mkdirSync(`${ft.env.USER_DATA_PATH}/a/b`, false)
} catch(e) {
  console.error(e)
}FileSystemManager.open 
FileSystemManager.open(Object object)
Open the file and return the file descriptor
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path (Local path) | |
| flag | string | r | no | File system flag, default: 'r' | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.flag Legal value
| value | Introductions | 
|---|---|
| a | Open the file for appending. If the file does not exist, create the file | 
| ax | Similar to 'a ', but fails if path exists | 
| a+ | Open the file for reading and appending. If the file does not exist, create the file | 
| ax+ | Similar to 'a + ', but fails if path exists | 
| as | Open the file for appending (in sync mode). If the file does not exist, create the file | 
| as+ | Open files for reading and appending (in synchronous mode). If the file does not exist, create the file | 
| r | Open the file for reading. If the file does not exist, an exception occurs | 
| r+ | Open files for reading and writing. If the file does not exist, an exception occurs | 
| w | Open the file for writing. Create a file if it does not exist, and truncate it if it exists | 
| wx | Similar to 'w ', but fails if path exists | 
| w+ | Open files for reading and writing. Create a file if it does not exist, and truncate it if it exists | 
| wx+ | Similar to 'w + ', but fails if path exists | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| fd | string | File descriptor | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.open({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+',
  success(res) {
    console.log(res.fd)
  }
})FileSystemManager.openSync 
FileSystemManager.openSync(Object object)
Open file synchronously, return file descriptor
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path (Local path) | |
| flag | string | r | no | File system flag, default: 'r' | 
object.flag Legal value
| value | Introductions | 
|---|---|
| a | Open the file for appending. If the file does not exist, create the file | 
| ax | Similar to 'a ', but fails if path exists | 
| a+ | Open the file for reading and appending. If the file does not exist, create the file | 
| ax+ | Similar to 'a + ', but fails if path exists | 
| as | Open the file for appending (in sync mode). If the file does not exist, create the file | 
| as+ | Open files for reading and appending (in synchronous mode). If the file does not exist, create the file | 
| r | Open the file for reading. If the file does not exist, an exception occurs | 
| r+ | Open files for reading and writing. If the file does not exist, an exception occurs | 
| w | Open the file for writing. Create a file if it does not exist, and truncate it if it exists | 
| wx | Similar to 'w ', but fails if path exists | 
| w+ | Open files for reading and writing. Create a file if it does not exist, and truncate it if it exists | 
| wx+ | Similar to 'w + ', but fails if path exists | 
Return value
string
File descriptor
sample code
javascript
const fs = ft.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+'
})
console.log(fd)FileSystemManager.read 
FileSystemManager.read(Object object)
Read Files
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| arrayBuffer | ArrayBuffer | yes | The buffer to which the data is written must be ArrayBuffer Example | |
| offset | number | 0 | no | Write offset in buffer, default 0 | 
| length | number | 0 | no | Number of bytes to read from the file, default 0 | 
| position | number | no | The starting position of a file read, such as no upload or upload Null, it is read from the position of the current file pointer. if position Is a positive integer, the file pointer position remains the same and is converted from the position Read the file. | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| bytesRead | number | Number of bytes actually read | 
| arrayBuffer | ArrayBuffer | Object that is written to the buffer, that is, the arrayBuffer | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
const ab = new ArrayBuffer(1024)
// Open the file
fs.open({
  filePath: `${ft.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+',
  success(res) {
    // Read file to ArrayBuffer in
    fs.read({
      fd: res.fd,
      arrayBuffer: AB,
      length: 10,
      success(res) {
        console.log(res)
      }
    })
  }
})FileSystemManager.readdir 
FileSystemManager.readdir(Object object)
Read list of files in a directory
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| dirPath | string | yes | Directory path to read (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| files | Array.<string> | Specifies an array of file names in a directory. | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.readdir({
  dirPath: `${ft.env.USER_DATA_PATH}/a`,
  success(res) {
    console.log(res.files)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.readdirSync 
FileSystemManager.readdirSync(string dirPath)
FileSystemManager.readdirSyncThe synchronised version of
parameter
string dirPath
Directory path to read (Local path)
Return value
Array.<string> files
Specifies an array of file names in a directory
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  const res = fs.readdirSync(`${ft.env.USER_DATA_PATH}/a`)
  console.log(res)
} catch(e) {
  console.error(e)
}FileSystemManager.readFile 
FileSystemManager.readFile(Object object)
Read local file content
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | Path to the file to read (Local path) | |
| encoding | string | binary | no | Specifies the character encoding for the read file, if the Encoding, the ArrayBuffer Format to read the binary contents of a file | 
| position | number | no | Start reading from the specified location in the file or from the file header if not specified. Read range should be left closed and right open range [position, position+length)。有效范围:[0, fileLength - 1]. Unit: byte | |
| length | number | no | Specifies the length of the file, if not specified, read to the end of the document. Scope of validity:[1, fileLength]. Unit: byte | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| data | string/ArrayBuffer | Document content | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.readFile({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  encoding: 'utf8',
  position: 0,
  success(res) {
    console.log(res.data)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.readFileSync 
FileSystemManager.readFileSync(string filePath, string encoding, number position, number length)
FileSystemManager.readFileSyncThe synchronised version of
parameter
string filePath
Path to the file to read (Local path)
string encoding
Specifies the character encoding for the read file, if the Encoding, the ArrayBuffer Format to read the binary contents of a file
encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
number position
Start reading from the specified location in the file or from the file header if not specified. Read range should be left closed and right open range [position, position+length)。Effective range:[0, fileLength - 1]. Unit: byte
number length
Specifies the length of the file, if not specified, read to the end of the document. Scope of validity:[1, fileLength]. Unit: byte
Return value
string|ArrayBuffer data
Document content
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  fs.copyFileSync(
    `${ft.env.USER_DATA_PATH}/test.txt`,
    `${ft.env.USER_DATA_PATH}/new-test.txt`
  )
} catch(e) {
  console.error(e)
}FileSystemManager.readSync 
FileSystemManager.readSync(Object object)
Read Files
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| arrayBuffer | ArrayBuffer | yes | The buffer to which the data is written must be ArrayBuffer Example | |
| offset | number | 0 | no | Write offset in buffer, default 0 | 
| length | number | 0 | no | Number of bytes to read from the file, default 0 | 
| position | number | no | The starting position of a file read, such as no upload or upload Null, it is read from the position of the current file pointer. if position Is a positive integer, the file pointer position remains the same and is converted from the position Read the file. | 
Return value
Object res
| attribute | type | Introductions | 
|---|---|---|
| bytesRead | number | Number of bytes actually read | 
| arrayBuffer | ArrayBuffer | The buffer to which the data is written must be ArrayBuffer Example | 
sample code
javascript
const fs = ft.getFileSystemManager()
const ab = new ArrayBuffer(1024)
const fd = fs.openSync({
  filePath: `${ft.env.USER_DATA_PATH}/hello.txt`,
  flag: 'a+'
})
const res = fs.readSync({
  fd: fd,
  arrayBuffer: ab,
  length: 10
})
console.log(res)FileSystemManager.removeSavedFile 
FileSystemManager.removeSavedFile(Object object)
Delete the saved local cache file under the Mini Program
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to delete (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.removeSavedFile({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.rename 
FileSystemManager.rename(Object object)
Rename the file. You can transfer files from oldPath Move to newPath
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| oldPath | string | yes | Source file path, support local path | |
| newPath | string | yes | New file path, support local path | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.rename({
  oldPath: `${ft.env.USER_DATA_PATH}/hello.txt`,
  newPath: `${ft.env.USER_DATA_PATH}/new-hello.txt`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.renameSync 
FileSystemManager.renameSync(string oldPath, string newPath)
FileSystemManager.renameThe synchronised version of
parameter
string oldPath
Source file path, support local path
string newPath
New file path, support local path
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  const res = fs.renameSync(
    `${ft.env.USER_DATA_PATH}/hello.txt`,
    `${ft.env.USER_DATA_PATH}/new-hello.txt`
  )
  console.log(res)
} catch(e) {
  console.error(e)
}FileSystemManager.rmdir 
FileSystemManager.rmdir(Object object)
Delete directory
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| dirPath | string | yes | Directory path to delete (Local path) | |
| recursive | boolean | false | no | Whether to recursively delete the directory. If for True, the directory and all subdirectories and files under it are deleted. | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.rmdir({
  dirPath: `${ft.env.USER_DATA_PATH}/a`,
  recursive: false,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.rmdirSync 
FileSystemManager.rmdirSync(string dirPath, boolean recursive)
FileSystemManager.rmdirThe synchronised version of
parameter
string dirPath
Directory path to delete (Local path)
boolean recursive
Whether to recursively delete the directory. If for True, the directory and all subdirectories and files under it are deleted
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  const res = fs.rmdirSync(`${ft.env.USER_DATA_PATH}/a`, false)
  console.log(res)
} catch(e) {
  console.error(e)
}FileSystemManager.saveFile 
FileSystemManager.saveFile(Object object)
Save temporary files locally. This interface moves temporary files, so when the call is successful, tempFilePath Will not be available
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| tempFilePath | string | yes | Temporary storage file path (Local path) | |
| filePath | string | no | File path to store (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| savedFilePath | string | File path after storage (Local path) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.saveFile({
  tempFilePath: `finfile:://temp/sample.text`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.saveFileSync 
FileSystemManager.saveFileSync(string tempFilePath, string filePath)
FileSystemManager.saveFileThe synchronised version of
parameter
string tempFilePath
Temporary storage file path (Local path)
string filePath
File path to store (Local path)
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  fs.saveFileSync( `finfile://temp/sample.txt`)
} catch(e) {
  console.error(e)
}FileSystemManager.stat 
FileSystemManager.stat(Object object)
Get file information object
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| path | string | yes | File/directory path (local path) | |
| recursive | boolean | false | no | Whether to recursively fetch information about each file in a directory | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| stats | object/Array.<object> | When recursive is false, res.stats yes an object. When recursive is true and path yes a path to a directory, res.stats yes an Array, one object per item yes of the array, each object containing path and stats. | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.stat({
  path: `${ft.env.USER_DATA_PATH}/test`,
  success: res => {
    console.log(res.stats)
  }
})
fs.stat({
  path: `${ft.env.USER_DATA_PATH}/test`,
  recursive: true,
  success: res => {
    Object.keys(res.stats).forEach(path => {
      let stats = res.stats[path]
      console.log(path, stats)
    })
  }
})FileSystemManager.statSync 
FileSystemManager.statSync(string path, boolean recursive)
FileSystemManager.statThe synchronised version of
parameter
string path
file/Directory path (Local path)
string recursive
For each file in the directory Stats information
Return value
object|Array.<object>
when recursive for false When res.stats It's a... Stats Object. when recursive for true and path Is a directory path, res.stats It's a... Array, each item in an array is an object, and each object contains path and stats
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  const res = fs.statSync(`${ft.env.USER_DATA_PATH}/sample`)
  console.log(res)
} catch(e) {
  console.error(e)
}FileSystemManager.truncate 
FileSystemManager.truncate(Object object)
Truncate file contents
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to truncate (Local path) | |
| length | number | 0 | yes | Truncate position, default 0. if length Less than the length of the file (bytes), only the front length Four bytes will remain in the file and the rest will be deletedif length Is greater than the file length, it will be expanded, and the extension will be filled with empty bytes0') | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.truncate({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  length: 10,
  success(res) {
    console.log(res)
  }
})FileSystemManager.truncateSync 
FileSystemManager.truncateSync(Object object)
FileSystemManager.truncateThe synchronised version of
parameter
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to truncate (Local path) | |
| length | number | 0 | yes | Truncate position, default 0. if length Less than the length of the file (bytes), only the front length Four bytes will remain in the file and the rest will be deletedif length Is greater than the file length, it will be expanded, and the extension will be filled with empty bytes0') | 
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  fs.truncateSync({
    filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
    length: 10,
  })
} catch(e) {
  console.error(e)
}FileSystemManager.unlink 
FileSystemManager.unlink(Object object)
Delete file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to delete (Local path) | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.unlink({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.unlinkSync 
FileSystemManager.unlinkSync(string filePath)
FileSystemManager.unlinkThe synchronised version of
parameter
string filePath
File path to delete (Local path)
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  const res = fs.unlinkSync(`${ft.env.USER_DATA_PATH}/test.txt`)
  console.log(res)
} catch(e) {
  console.error(e)
}FileSystemManager.unzip 
FileSystemManager.unzip(Object object)
Decompress file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| zipFilePath | string | yes | Source file path, support local path, It can only be zip Compressed file | |
| targetPath | string/ArrayBuffer | yes | Destination directory path, Support local path | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.unzip({
  zipFilePath: `${ft.env.USER_DATA_PATH}/sample.zip`,
  targetPath: `${ft.env.USER_DATA_PATH}/sample`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.write 
FileSystemManager.write(Object object)
Write file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| data | string/ArrayBuffer | yes | Write content of type String or ArrayBuffer | |
| offset | number | 0 | no | Only in data Type is ArrayBuffer When valid, decided arrayBuffe To be written to in the arrayBuffer Index in, default 0 | 
| length | number | no | Only in data Type is ArrayBuffer Specifies the number of bytes to write, and defaults to arrayBuffer Offset from 0 offset Number of bytes remaining after 1 byte | |
| encoding | string | utf-8 | no | Only in data Type is String Specifies the character encoding to write to the file, and defaults to utf8 | 
| position | number | no | Specifies the offset at the beginning of the file, where the data will be written. when position Not passed or passed in Number Type, the data is written to the current pointer location. | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| bytesWritten | number | Number of bytes actually written to the file (note that the number of byte writes is not necessarily the same as the string characters written) | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.open({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+',
  success(res) {
    // Write file
    fs.write({
      fd: res.fd,
      data: 'this is text',
      success(res) {
        console.log(res.bytesWritten)
      }
    })
  }
})FileSystemManager.writeFile 
FileSystemManager.writeFile(Object object)
Write file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| filePath | string | yes | File path to write to (Local path) | |
| data | string/ArrayBuffer | yes | Text or binary data to write | |
| encoding | string | utf-8 | no | Specifies the character encoding for writing to the file | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
object.fail callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
sample code
javascript
const fs = ft.getFileSystemManager()
fs.writeFile({
  filePath: `${ft.env.USER_DATA_PATH}/hello.txt`,
  data: 'some text or arrayBuffer',
  encoding: 'utf8',
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})FileSystemManager.writeFileSync 
FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding)
FileSystemManager.writeFileThe synchronised version of
parameter
string filePath
File path to write to (Local path)
string|ArrayBuffer data
Text or binary data to write
string encoding
Specifies the character encoding for writing to the file
object.encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
sample code
javascript
const fs = ft.getFileSystemManager()
// Synchronous interface
try {
  const res = fs.writeFileSync(
    `${ft.env.USER_DATA_PATH}/test.txt`,
    'some text or arrayBuffer',
    'utf8'
  )
  console.log(res)
} catch(e) {
  console.error(e)
}FileSystemManager.writeSync 
FileSystemManager.writeSync(Object object)
Synchronous write file
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| fd | string | yes | File descriptor that needs to be closed. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
| data | string/ArrayBuffer | yes | Write content of type String or ArrayBuffe | |
| offset | number | 0 | no | Only in data Type is ArrayBuffer When valid, decided arrayBuffe To be written to in the arrayBuffer Index in, default 0 | 
| length | number | no | Only in data Type is ArrayBuffer Specifies the number of bytes to write, and defaults to arrayBuffer Offset from 0 offset Number of bytes remaining after 1 byte | |
| encoding | string | utf-8 | no | Only in data Type is String Specifies the character encoding to write to the file, and defaults to utf8 | 
| position | number | no | Specifies the offset at the beginning of the file, where the data will be written. when position Not passed or passed in Number Type, the data is written to the current pointer location. | 
object.encoding Legal value
| value | Introductions | 
|---|---|
| base64 | |
| binary | |
| utf-8 | |
| utf8 | 
Return value
Object res
| attribute | type | Introductions | 
|---|---|---|
| bytesWritten | number | The actual number of bytes written to the file (note that the number of bytes written is not necessarily the same as the number of characters in the string being written) | 
sample code
javascript
const fs = ft.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${ft.env.USER_DATA_PATH}/test.txt`,
  flag: 'a+'
})
const res = fs.writeSync({
  fd: fd,
  data: 'this is text'
})
console.log(res)