# ReadResult FileSystemManager.readSync(Object object)

Start from base library version 2.16.1. Please remaining backward compatible.

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2

Read Files

# parameter

# Object object

attribute type Default values Required Introductions
初始值 string yes File descriptor. 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

# ReadResult

File Read Results

# error

Error code Error message Introductions
bad file descriptor Invalid file descriptor
fail permission denied Specified fd Path not read
fail the value of "offset" is out of range Incoming offset illegal
fail the value of "length" is out of range Incoming length illegal
fail sdcard not mounted android sdcard Mount failure
bad file descriptor Invalid file descriptor

# sample code

const fs = wx.getFileSystemManager()
const ab = new ArrayBuffer(1024)
const fd = fs.openSync({
  filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+'
})
const res = fs.readSync({
  fd: fd,
  arrayBuffer: AB,
  length: 10
})
console.log(res)