Skip to main content
Version: v3

writeFileSync

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Synchronously write data to a file in the /data directory of the Mini Program, replacing the file if it already exists, or creating a new file if it doesn't.

Type

function writeFileSync(option: Option): void

Parameters

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
pathstring|numberY-File path or file descriptor2.0
dataArrayBuffer|string|DataViewY-Data to be written to the target file2.0
optionsOptionsN-Other Options2.0

Options

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
encodingstringNutf8If the data format is string, you need to specify the encoding method2.0

Example

import { writeFileSync } from '@zos/fs'

const buffer = new ArrayBuffer(4)
writeFileSync({
path: 'test.txt',
data: buffer,
})

writeFileSync({
path: 'content.txt',
data: 'some content...',
options: {
encoding: 'utf8',
},
})