Skip to main content
版本:v2

readFileSync

API_LEVEL 2.0 开始支持,API 兼容性请参考 API_LEVEL。

返回小程序 /data 目录下指定文件的全部内容。

类型​

function readFileSync(option: Option): Result

参数​

Option​

属性类型必填默认值说明API_LEVEL
pathstring是-文件路径2.0
optionsOptions否-其他选项2.0

Options​

属性类型必填默认值说明API_LEVEL
encodingstring否-当指定了编码方式之后,API 返回结果为 string2.0

Result​

类型说明
ArrayBuffer|string|undefined文件内容。如果返回 undefined,则表明读取文件失败

代码示例​

import { readFileSync } from '@zos/fs'

const contentBuffer = readFileSync({
path: 'test.txt',
})

const contentString = readFileSync({
path: 'test.txt',
options: {
encoding: 'utf8',
},
})