HomeDocs
Skip to main content

FileSystemManager.close

Introduction

Closes a file.

Usage Restrictions

Requires basic library version 3.0.0 or higher.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
fdstringYesFile descriptor. fd is obtained through the FileSystemManager.open interface
successfunctionNoCallback function for successful API call
failfunctionNoCallback function for failed API call
completefunctionNoCallback function called after API call completion (executed regardless of success or failure)

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue-Successful

object.fail

Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstringError message
successstringfalse-Failed

errMsg Description

Error messageExplanation
parameter error: F10001Invalid parameter
bad file descriptor: F10003Invalid file descriptor

Sample Code

// pages/index/index.js
Page({
close() {
// Open file
const fs = dlt.getFileSystemManager();
fs.open({
filePath: `${dlt.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success: (res) => {
// Close file
fs.close({
fd: res.fd,
});
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.