FileSystemManager.close
Introduction
Closes a file.
Usage Restrictions
Requires basic library version 3.0.0
or higher.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
fd | string | Yes | File descriptor. fd is obtained through the FileSystemManager.open interface | |
success | function | No | Callback function for successful API call | |
fail | function | No | Callback function for failed API call | |
complete | function | No | Callback function called after API call completion (executed regardless of success or failure) |
object.success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true-Successful |
object.fail
Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
errMsg | string | Error message |
success | string | false-Failed |
errMsg Description
Error message | Explanation |
---|---|
parameter error: F10001 | Invalid parameter |
bad file descriptor: F10003 | Invalid 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);
},
});
},
});