This method is used via wx.saveFile(Object object)
Attribute | Type | Default value | Required | Description |
tempFilePath | string | - | Yes | Temporary path for the files that need to be stored |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
savedFilePath | string | File path after storage |
wx.chooseImage({success(res) {const tempFilePaths = res.tempFilePathswx.saveFile({tempFilePath: tempFilePaths[0],success(res) {const savedFilePath = res.savedFilePath}})}})
This method is used via wx.removeSavedFile(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Path for the files that need to be deleted. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
wx.getSavedFileList({success(res) {if (res.fileList.length > 0) {wx.removeSavedFile({filePath: res.fileList[0].filePath,complete(res) {console.log(res)}})}}})
This API is used via wx.openDocument(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path to the file (local path), which can be obtained from downloadFile. |
fileType | string | - | No | File type, used to open the file of specified type. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
pdf | PDF format |
wx.downloadFile({// Example url, not realurl: 'https://example.com/somefile.pdf',success(res) {const filePath = res.tempFilePathwx.openDocument({filePath,success(res) {console.log('Opened document successfully')}})}})
This method is used via wx.getSavedFileList(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
fileList | Array.<Object> | File array, with each item being a FileItem. |
Attribute | Type | Description |
filePath | string | Local path |
size | number | Local file size, measured in bytes. |
createTime | number | Timestamp for file saving, denoting the number of seconds from 08:00:00 on Jan. 01, 1970 to the current time. |
wx.getSavedFileList({success(res) {console.log(res.fileList)}})
This method is used via wx.getSavedFileInfo(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | File path |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
size | number | File size measured in bytes. |
createTime | number | Timestamp for file saving, denoting the number of seconds from 08:00:00 on Jan. 01, 1970 to the current time. |
wx.getSavedFileList({success(res) {console.log(res.fileList)}})
The API is used via wx.getFileInfo(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Local File Path |
digestAlgorithm | string | 'md5' | No | Algorithm for calculating file digest. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
md5 | MD5 Algorithm |
sha1 | SHA1 Algorithm |
Attribute | Type | Description |
size | number | File size, measured in bytes. |
digest | string | File digest calculated according to the provided digestAlgorithm |
wx.getFileInfo({success(res) {console.log(res.size)console.log(res.digest)}})
The API is used via FileSystemManager wx.getFileSystemManager().
This method is used via FileSystemManager.access(Object object).
Attribute | Type | Default value | Required | Description |
path | string | - | Yes | The file/directory path to be determined for existence. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory ${path} | The file/directory does not exist. |
bad file descriptor | Invalid file descriptors |
permission denied | Permission error, file is read-only or write-only |
permission denied, cannot access file path | Destination path without access rights (usr directory) |
not a directory | dirPath specifies that the path is not a directory, which is common when the parent path of the specified write path is a file. |
Invalid argument | Invalid parameter to check if length or offset is out of bounds |
directory not empty | directory not empty |
the maximum size of the file storage limit is exceeded | the maximum size of the file storage limit is exceeded |
base64 encode error | Character encoding conversion failure (e.g. base64 format error) |
data to write is empty | data to write is empty |
illegal operation on a directory | This must not be done for directories (e.g., the specified filePath is an existing directory) |
file already exists ${dirPath} | A file or directory with the same name already exists |
value of length is out of range | value of length is out of range |
value of offset is out of range | value of offset is out of range |
value of position is out of range | value of position is out of range |
const fs = wx.getFileSystemManager()// Determine if the file/directory existsfs.access({path: `${wx.env.USER_DATA_PATH}/hello.txt`, success(res) {success(res) {// The file existsconsole.log(res)}, fail(res) { // File exists.fail(res) {// File does not exist or other errorconsole.error(res)}})// Synchronization interfacetry {fs.accessSync(`${wx.env.USER_DATA_PATH}/hello.txt`)} catch(e) {console.error(e)}
This method is used via FileSystemManager.accessSync(string path).
const fs = wx.getFileSystemManager()// Determine if the file/directory existsfs.access({path: `${wx.env.USER_DATA_PATH}/hello.txt`, success(res) {success(res) {// The file existsconsole.log(res)}, fail(res) { // File exists.fail(res) {// File does not exist or other errorconsole.error(res)}})// Synchronization interfacetry {fs.accessSync(`${wx.env.USER_DATA_PATH}/hello.txt`)} catch(e) {console.error(e)}
This method is used via FileSystemManager.appendFile(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path of file to which content is to be appended. |
data | string/ArrayBuffer | - | Yes | The text or binary data to be appended. |
encoding | string | utf-8 | No | Specifies the character encoding for the file to be written. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory, open ${filePath} | The specified filePath file does not exist. |
fail illegal operation on a directory, open "${filePath}" | The specified filePath is an existing directory. |
fail permission denied, open ${dirPath} | The specified filePath does not have write permissions. |
fail sdcard not mounted | The specified filePath is an existing directory. |
const fs = wx.getFileSystemManager()fs.appendFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {fs.appendFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8')} catch(e) {console.error(e)}
This method is used via FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding).
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
const fs = wx.getFileSystemManager()fs.appendFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {fs.appendFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8')} catch(e) {console.error(e)}
This method is used via FileSystemManager.close(Object object)
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor that needs to be closed. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
const fs = wx.getFileSystemManager()// Open the filefs.open({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+',success(res) {// Close the filefs.close({fd: res.fd})}})
This method is used via undefined FileSystemManager.closeSync(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor that needs to be closed. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath:$
{
wx
.
env
.
USER_DATA_PATH
}
/
hello
.
txt
,flag: 'a+'})// Close the filefs.closeSync({fd: fd})
This method is used via FileSystemManager.copyFile(Object object).
Attribute | Type | Default value | Required | Description |
srcPath | string | - | Yes | Source file path, which can only be a regular file. |
destPath | string | - | Yes | Destination file path, support local path |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail permission denied, copyFile ${srcPath} -> ${destPath} | The specified destination file path does not have write permissions. |
fail no such file or directory, copyFile ${srcPath} -> ${destPath} | The source file does not exist, or the parent directory of the destination file path does not exist. |
const fs = wx.getFileSystemManager()fs.copyFile({srcPath: `${wx.env_USER_DATA_PATH}/hello.txt`、destPath:`${wx.env.USER_DATA_PATH}/hello_copy.txt`。success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {fs.copyFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`、`${wx.env.USER_DATA_PATH}/hello_copy.txt`。${wx.env.USER_DATA_PATH}/hello_copy.txt`.)} catch(e) {console.error(e)}
This method is used via FileSystemManager.copyFileSync(string srcPath, string destPath).
const fs = wx.getFileSystemManager()fs.copyFile({srcPath: `${wx.env_USER_DATA_PATH}/hello.txt`、destPath:`${wx.env.USER_DATA_PATH}/hello_copy.txt`。success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {fs.copyFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`、`${wx.env.USER_DATA_PATH}/hello_copy.txt`。${wx.env.USER_DATA_PATH}/hello_copy.txt`.)} catch(e) {console.error(e)}
This method is used via FileSystemManager.getFileInfo(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path of the file to be read. |
digestAlgorithm | string | md5 | No | Algorithms for calculating document summaries |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
md5 | md5 algorithm |
sha1 | sha1 algorithm |
Attribute | Type | Description |
size | number | File size, measured in bytes. |
digest | string | File digest calculated according to the passed digestAlgorithm |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail file not exist | The file is not found in the specified filePath. |
no such file or directory ${path} | File/directory does not exist, or the upper directory of the target file path does not exist |
Input/output error | Input or output streams not available |
permission denied | Permission error, file is read-only or write-only |
Path permission denied | The incoming path has no permissions |
not a directory | dirPath specifies that the path is not a directory, which is common when the parent path of the specified write path is a file. |
Invalid argument | Invalid parameter to check if length or offset is out of bounds |
excced max concurrent fd limit | The number of fd's has reached its limit |
This method is used via FileSystemManager.fstat(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
stats | Get the Stats object of the file, which contains the status information of the file. |
const fs = wx.getFileSystemManager()// Open the filefs.open({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+',success(res) {// Get the status information of the file.fs.fstat({fd: res.fd,success(res) {console.log(res.stats)}})}})
This method is used via Stats FileSystemManager.fstatSync(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+'})const stats = fs.fstatSync({fd: fd})console.log(stats)
This method is used via FileSystemManager.ftruncate(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
length | number | - | Yes | By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0'). |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
const fs = wx.getFileSystemManager()// Open the filefs.open({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+',success(res) {//Truncate the file content.fs.ftruncate({fd: res.fd,length: 10, // Truncate the file starting from the 10th bytesuccess(res) {console.log(res)}})}})
This method is used via undefined FileSystemManager.ftruncateSync(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
length | number | - | Yes | By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0'). |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+'})fs.ftruncateSync({fd: fd,length: 10// Truncate the file starting from the 10th byte})
This method is used via FileSystemManager.getSavedFileList(Object object).
Attribute | Type | Default value | Required | Description |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
fileList | Array.<Object> | Array of files |
Attribute | Type | Description |
filePath | string | Local path |
size | number | Local file size, measured in bytes. |
createTime | number | Timestamp for file saving, denoting the number of seconds from 08:00:00 on Jan. 01, 1970 to the current time. |
This method is used via FileSystemManager.mkdir(Object object).
Attribute | Type | Default value | Required | Description |
dirPath | string | - | Yes | Path of the created directory. |
recursive | boolean | false | No | Whether to create the directory after recursively creating its parent directory. If the corresponding parent directory already exists, this parent directory will not be created. For instance, if dirPath is a/b/c/d and recursive is true, it will create directory a, then create directory b under a, and so forth until directory d under a/b/c is created. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory ${dirPath} | Parent directory does not exist. |
fail permission denied, open ${dirPath} | The specified filePath does not have write permissions. |
fail file already exists ${dirPath} | There exists a file or directory with the same name. |
const fs = wx.getFileSystemManager()fs.mkdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {fs.mkdirSync(`${wx.env.USER_DATA_PATH}/example`, false)} catch(e) {console.error(e)}
This method is used via FileSystemManager.mkdirSync(string dirPath, boolean recursive).
const fs = wx.getFileSystemManager()fs.mkdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {fs.mkdirSync(`${wx.env.USER_DATA_PATH}/example`, false)} catch(e) {console.error(e)}
This method is used via FileSystemManager.open(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | File path (local path) |
flag | string | r | No | File system flag, default value: r |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Valid Values | Description |
a | Opens a file for appending. If the file does not exist, it creates the file. |
ax | Similar to 'a', but will fail if the path exists. |
a+ | Opens a file for reading and appending. If the file does not exist, it creates the file. |
ax+ | Similar + to 'a', but will fail if the path exists. |
as | Opens a file for appending (in the syncing mode). If the file does not exist, it creates the file. |
as+ | Opens a file for both reading and appending (in the syncing mode). If the file does not exist, it creates the file. |
r | Opens a file for reading. If the file does not exist, an exception occurs. |
r+ | Opens a file for reading and writing. If the file does not exist, an exception occurs. |
w | Opens a file for writing. If the file does not exist, it creates the file; if the file exists, it truncates the file. |
wx | Similar to 'w', but will fail if the path exists. |
w+ | Opens a file for reading and writing. If the file does not exist, it creates the file; if the file exists, it truncates the file. |
wx+ | Similar to 'w+', but will fail if the path exists. |
Attribute | Type | Description |
fd | string | File descriptor |
const fs = wx.getFileSystemManager()fs.open({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+',success(res) {console.log(res.fd)}})
This method is used via string FileSystemManager.openSync(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | File path (local path) |
flag | string | r | No | File system flag, default value: r |
Valid Values | Description |
a | Opens a file for appending. If the file does not exist, it creates the file. |
ax | Similar to 'a', but will fail if the path exists. |
a+ | Opens a file for reading and appending. If the file does not exist, it creates the file. |
ax+ | Similar + to 'a', but will fail if the path exists. |
as | Opens a file for appending (in the syncing mode). If the file does not exist, it creates the file. |
as+ | Opens a file for both reading and appending (in the syncing mode). If the file does not exist, it creates the file. |
r | Opens a file for reading. If the file does not exist, an exception occurs. |
r+ | Opens a file for reading and writing. If the file does not exist, an exception occurs. |
w | Opens a file for writing. If the file does not exist, it creates the file; if the file exists, it truncates the file. |
wx | Similar to 'w', but will fail if the path exists. |
w+ | Opens a file for reading and writing. If the file does not exist, it creates the file; if the file exists, it truncates the file. |
wx+ | Similar to 'w+', but will fail if the path exists. |
const fs = wx.getFileSystemManager() const fd = fs.openSync({ filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, flag: 'a+' }) console.log(fd)
This method is used via FileSystemManager.read(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
arrayBuffer | ArrayBuffer | - | Yes | The buffer for data writing must be an instance of ArrayBuffer. |
offset | number | 0 | No | The write offset in the buffer, with the default value being 0. |
length | number | 0 | No | The number of bytes to read from the file, with the default value being 0. |
position | number | - | No | The starting position of the file to be read, if not passed or if null is passed, then the file will be read from the current position of the file pointer. If position is a positive integer, the position of the file pointer will remain unchanged and the file will be read from position. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
bytesRead | number | The actual number of bytes read. |
arrayBuffer | ArrayBuffer | The object of the buffer being written to, that is, the arrayBuffer parameter of the interface. |
const fs = wx.getFileSystemManager()const ab = new ArrayBuffer(1024)// Open the filefs.open({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+',success(res) {//Read the file into the ArrayBufferfs.read({fd: res.fd,arrayBuffer: ab,length: 10,success(res) {console.log(res)}})}})
This method is used via ReadResult FileSystemManager.readSync(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
arrayBuffer | ArrayBuffer | - | Yes | The buffer for data writing must be an instance of ArrayBuffer. |
offset | number | 0 | No | The write offset in the buffer, with the default value being 0. |
length | number | 0 | No | The number of bytes to read from the file, with the default value being 0. |
position | number | - | No | The starting position for file reading. If not provided or null, the file will be read from the current file pointer position. If the position is a positive integer, the file pointer position will remain unchanged and the file will be read from the position. |
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)
This method is used via FileSystemManager.readCompressedFile(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path of the file to be read (local user file or code package file). |
compressionAlgorithm | string | - | Yes | File compression type, currently only supported br |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Legal values | Description |
br | brotli zip file |
Attribute | Type | Description |
data | ArrayBuffer | Version content |
const fs = wx.getFileSystemManager()//Asynchronous Interfacefs.readCompressedFile({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',success(res) {console.log(res.data)},fail(res) {console.log('readCompressedFile fail', res)}})//Synchronous Interfaceconst data = fs.readCompressedFileSync({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',})console.log(data)
This method is used via ArrayBuffer FileSystemManager.readCompressedFileSync(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path of the file to be read (local user file or code package file). |
compressionAlgorithm | string | - | Yes | File compression type, currently only supported br |
Legal values | Description |
br | brotli zip file |
const fs = wx.getFileSystemManager()//Asynchronous Interfacefs.readCompressedFile({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',success(res) {console.log(res.data)},fail(res) {console.log('readCompressedFile fail', res)}})//Synchronous Interfacetry {const data = fs.readCompressedFileSync({filePath: '${wx.env.USER_DATA_PATH}/hello.br',compressionAlgorithm: 'br',})console.log(data)} catch (err) {console.log(err)}
This method is used via FileSystemManager.readdir(Object object).
Attribute | Type | Default value | Required | Description |
dirPath | string | - | Yes | The directory path to be read. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
files | Array.\\<string> | An array of file names in the specified directory. |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory ${dirPath} | The directory does not exist. |
fail not a directory ${dirPath} | dirPath is not a directory. |
fail permission denied, open ${dirPath} | The specified filePath does not have read permissions. |
const fs = wx.getFileSystemManager()fs.readdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,success(res) {console.log(res.files)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)console.log(res)} catch(e) {console.error(e)}
This method is used via Array.<string> FileSystemManager.readdirSync(string dirPath).
const fs = wx.getFileSystemManager()fs.readdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,success(res) {console.log(res.files)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.readFile(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path of the file to be read. |
encoding | string | - | No | Specifies the character encoding for reading the file. If encoding is not provided, the file's binary content is read in ArrayBuffer format. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Attribute | Type | Description |
data | string/ArrayBuffer | Version content |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory, open ${filePath} | The directory of the specified filePath does not exist. |
fail permission denied, open ${dirPath} | The specified filePath does not have read permissions. |
const fs = wx.getFileSystemManager()fs.readFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,encoding: 'utf8',position: 0,success(res) {console.log(res.data)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.readFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'utf8', 0)console.log(res)} catch(e) {console.error(e)}
This method is used via string|ArrayBuffer FileSystemManager.readFileSync(string filePath, string encoding).
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
const fs = wx.getFileSystemManager()fs.readFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,encoding: 'utf8',position: 0,success(res) {console.log(res.data)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.readFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'utf8', 0)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.readZipEntry(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | The path of the compressed package to be read (local path). |
encoding | string | - | No | Uniformly specifies the character encoding for reading the file, effective only when the entries value is "all". If the entries value is "all" and encoding is not provided, the file's binary content is read in ArrayBuffer format. |
entries | Array.<Object>/'all' | - | Yes | The list of files within the compressed package to be read (when "all" is passed in, it signifies reading all files within the compressed package). |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Structure attributes | Type | Default value | Required | Description |
path | string | - | Yes | Path of the file within the compressed package. |
encoding | string | - | No | Specify the character encoding of the file to be read, if encoding is not passed, the binary content of the file will be read in ArrayBuffer format, the legal value is the same as encoding. |
position | number | - | No | Start reading from a specified position in the file; if not specified, reading begins from the start of the file. The reading range should be a left-closed and right-open interval [position, position+length). The valid range is [0, fileLength - 1] in bytes. |
length | number | - | No | Specify the length of the file. If not specified, reading continues until the end of the file. The valid range is [1, fileLength] in bytes. |
Attribute | Type | Description |
entries | Object | The result of the file reading. 'res.entries' is an object where the key is the file path and the value is an object 'FileItem', representing the reading result of that file. Each 'FileItem' includes 'data' (file content) and 'errMsg' (error information) attributes. |
Structure attributes | Type | Description |
path | string | File path |
Structure attributes | Type | Description |
data | string/ArrayBuffer | Version content |
errMsg | string | Error Message |
const fs = wx.getFileSystemManager()// Read one or multiple files within a zip.fs.readZipEntry({filePath: 'wxfile://from/to.zip',entries: [{path: 'some_folder/my_file.txt', // File path within the zipencoding: 'utf-8', // Specifies the character encoding for reading the file. If 'encoding' is not passed, the file's binary content is read in ArrayBuffer formatposition: 0, // Start reading from a specified position in the file; if not specified, reading begins from the start of the file. The reading range should be a left-closed and right-open interval [position, position+length). The valid range is [0, fileLength - 1] in bytes.length: 10000, // Specify the length of the file. If not specified, reading continues until the end of the file. The valid range is [1, fileLength] in bytes.}, {path: 'other_folder/orther_file.txt', // File path within the zip}],success(res) {console.log(res.entries)// res.entries === {// 'some_folder/my_file.txt': {// errMsg: 'readZipEntry:ok',// data: 'xxxxxx'// },// 'other_folder/orther_file.txt': {// data: (ArrayBuffer)// }// }},fail(res) {console.log(res.errMsg)},})// Reads all files within the zip. A unified 'encoding' can be specified. 'Position' and 'length' can no longer be specified and default to 0 and the file length, respectively.fs.readZipEntry({filePath: 'wxfile://from/to.zip',entries: 'all'encoding: 'utf-8', // Uniformly specifies the character encoding for reading the file. If 'encoding' is not passed, the file's binary content is read in ArrayBuffer format.success(res) {console.log(res.entries)// res.entries === {// 'some_folder/my_file.txt': {// errMsg: 'readZipEntry:ok',// data: 'xxxxxx'// },// 'other_folder/orther_file.txt': {// errMsg: 'readZipEntry:ok',// data: 'xxxxxx'// }// }},fail(res) {console.log(res.errMsg)},})
This method is used via FileSystemManager.removeSavedFile(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Path for the files that need to be deleted. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail file not exist | The file is not found in the specified tempFilePath. |
This method is used via FileSystemManager.rename(Object object).
Attribute | Type | Default value | Required | Description |
oldPath | string | - | Yes | Source file path, can be a common file or directory, support local paths |
newPath | string | - | Yes | New file path, local path support |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail permission denied, rename ${oldPath} -> ${newPath} | The specified source file or target file does not have write permissions. |
fail no such file or directory, rename ${oldPath} -> ${newPath} | The source file does not exist, or the parent directory of the destination file path does not exist. |
const fs = wx.getFileSystemManager()fs.rename({oldPath: `${wx.env.USER_DATA_PATH}/hello.txt`,newPath: `${wx.env.USER_DATA_PATH}/hello_new.txt`,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.renameSync(`${wx.env.USER_DATA_PATH}/hello.txt`,`${wx.env.USER_DATA_PATH}/hello_new.txt`)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.renameSync(string oldPath, string newPath).
const fs = wx.getFileSystemManager()fs.rename({oldPath: `${wx.env.USER_DATA_PATH}/hello.txt`,newPath: `${wx.env.USER_DATA_PATH}/hello_new.txt`,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.renameSync(`${wx.env.USER_DATA_PATH}/hello.txt`,`${wx.env.USER_DATA_PATH}/hello_new.txt`)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.rmdir(Object object).
Attribute | Type | Default value | Required | Description |
dirPath | string | - | Yes | The path of directory to be deleted. |
recursive | boolean | false | No | Determines whether to recursively delete the directory. If set to true, it will delete the directory along with all its subdirectories and files. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory ${dirPath} | The directory does not exist. |
fail directory not empty | The directory is not empty. |
fail permission denied, open ${dirPath} | The specified dirPath does not have write permissions. |
const fs = wx.getFileSystemManager()fs.rmdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.rmdirSync(`${wx.env.USER_DATA_PATH}/example`, false)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.rmdirSync(string dirPath, boolean recursive).
const fs = wx.getFileSystemManager()fs.rmdir({dirPath: `${wx.env.USER_DATA_PATH}/example`,recursive: false,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.rmdirSync(`${wx.env.USER_DATA_PATH}/example`, false)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.saveFile(Object object).
Attribute | Type | Default value | Required | Description |
tempFilePath | string | - | Yes | The path for temporary file storage. |
filePath | string | - | No | Path of files to be stored. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
savedFilePath | number | File path after storage |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail tempFilePath file not exist | The file is not found in the specified tempFilePath. |
fail permission denied, open "${filePath}" | The specified filePath does not have write permissions. |
fail no such file or directory "${dirPath}" | Parent directory does not exist. |
This method is used via number FileSystemManager.saveFileSync(string tempFilePath, string filePath).
This method is used via FileSystemManager.stat(Object object).
Attribute | Type | Default value | Required | Description |
path | string | - | Yes | Path of file/directory |
recursive | boolean | false | No | Whether to recursively get the Stats information of each file in the directory. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
stats | Stats/Object | When recursive is false, res.stats is a Stats object. When recursive is true and path is a directory path, res.stats is an Object, with the key being the relative path rooted at path, and the value being the Stats object corresponding to that path. |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail permission denied, open ${path} | The specified path does not have read permissions. |
fail no such file or directory ${path} | The file does not exist. |
// Asynchronous versionlet fs = wx.getFileSystemManager()fs.stat({path: `${wx.env.USER_DATA_PATH}/testDir`,success: res => {console.log(res.stats.isDirectory())}})// Synchronise versionsfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, false)
let fs = wx.getFileSystemManager()// Asynchronous versionfs.stat({path: `${wx.env.USER_DATA_PATH}/testDir`,recursive: true,success: res => {Object.keys(res.stats).forEach(path => {let stats = res.stats[path]console.log(path, stats.isDirectory())})}})// Synchronise versionsfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, true)
This method is used via Stats|Object FileSystemManager.statSync(string path, boolean recursive).
// Asynchronous versionlet fs = wx.getFileSystemManager()fs.stat({path: `${wx.env.USER_DATA_PATH}/testDir`,success: res => {console.log(res.stats.isDirectory())}})// Synchronise versionsfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, false)
let fs = wx.getFileSystemManager()// Asynchronous versionfs.stat({path: `${wx.env.USER_DATA_PATH}/testDir`,recursive: true,success: res => {Object.keys(res.stats).forEach(path => {let stats = res.stats[path]console.log(path, stats.isDirectory())})}})// Synchronise versionsfs.statSync(`${wx.env.USER_DATA_PATH}/testDir`, true)
This method is used via FileSystemManager.truncate(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Path of the file to be truncated (local path) |
length | number | 0 | No | By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0'). |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
const fs = wx.getFileSystemManager()fs.truncate({filePath:$
{
wx
.
env
.
USER_DATA_PATH
}
/
hello
.
txt
,length: 10, // Truncate the file starting from the 10th bytesuccess(res) {console.log(res)}})
This method is used via undefined FileSystemManager.truncateSync(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | | Yes | Path of the file to be truncated (local path) |
length | number | 0 | No | By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0'). |
const fs = wx.getFileSystemManager()fs.truncateSync({filePath:$
{
wx
.
env
.
USER_DATA_PATH
}
/
hello
.
txt
,length: 10, // Truncate the file starting from the 10th byte})
This method is used via FileSystemManager.unlink(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Path for the files that need to be deleted. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail permission denied, open ${path} | The specified path does not have read permissions. |
fail no such file or directory ${path} | The file does not exist. |
fail operation not permitted, unlink ${filePath} | The filePath passed in is a directory. |
const fs = wx.getFileSystemManager()fs.unlink({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.unlinkSync(`${wx.env.USER_DATA_PATH}/hello.txt`)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.unlinkSync(string filePath).
const fs = wx.getFileSystemManager()fs.unlink({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.unlinkSync(`${wx.env.USER_DATA_PATH}/hello.txt`)console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.unzip(Object object).
Attribute | Type | Default value | Required | Description |
zipFilePath | string | - | Yes | Source file path, which can only be a zip compressed file. |
targetPath | string | - | Yes | Path of destination directory. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail permission denied, unzip ${zipFilePath} -> ${destPath} | The specified destination file path does not have write permissions. |
fail no such file or directory, unzip ${zipFilePath} -> ${destPath} | The source file does not exist, or the parent directory of the destination file path does not exist. |
const fs = wx.getFileSystemManager()fs.unzip({zipFilePath: `${wx.env.USER_DATA_PATH}/example.zip`,targetPath: '${wx.env.USER_DATA_PATH}/example',success(res) {console.log(res)},fail(res) {console.error(res)}})
This method is used via FileSystemManager.write(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
data | string/ArrayBuffer | - | Yes | The text or binary data to be written in. |
offset | number | - | No | Only effective when the data type is ArrayBuffer, it determines the part to be written in the ArrayBuffer, that is, the index in the ArrayBuffer, with the default value being 0. |
length | number | - | No | Only effective when the data type is ArrayBuffer, it specifies the number of bytes to be written, defaulting to the remaining bytes after offsetting the ArrayBuffer from 0 by the specified bytes at the offset value. |
encoding | string | utf8 | No | Specifies the character encoding for the file to be written. |
position | number | - | No | Specifies the offset at the beginning of the file, that is, the position where the data is to be written. When position is not passed or a non-Number type value is passed, the data will be written at the current pointer location. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Attribute | Type | Description |
bytesWritten | number | The actual number of bytes written into the file (note, the number of bytes written may not necessarily be the same as the number of characters in the written string). |
const fs = wx.getFileSystemManager()// Open the filefs.open({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+',success(res) {// Write in files.fs.write({fd: res.fd,data: 'some text',success(res) {console.log(res.bytesWritten)}})}})
This method is used via FileSystemManager.writeFile(Object object).
Attribute | Type | Default value | Required | Description |
fd | string | - | Yes | The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface. |
data | string/ArrayBuffer | - | Yes | The text or binary data to be written in. |
offset | number | - | No | Only effective when the data type is ArrayBuffer, it determines the part to be written in the ArrayBuffer, that is, the index in the ArrayBuffer, with the default value being 0. |
length | number | - | No | Only effective when the data type is ArrayBuffer, it specifies the number of bytes to be written, defaulting to the remaining bytes after offsetting the ArrayBuffer from 0 by the specified bytes at the offset value. |
encoding | string | utf8 | No | Specifies the character encoding for the file to be written. |
position | number | - | No | Specifies the offset at the beginning of the file, that is, the position where the data is to be written. When position is not passed or a non-Number type value is passed, the data will be written at the current pointer location. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Attribute | Type | Description |
bytesWritten | number | The actual number of bytes written into the file (note, the number of bytes written may not necessarily be the same as the number of characters in the written string). |
const fs = wx.getFileSystemManager()const fd = fs.openSync({filePath:${wx.env.USER_DATA_PATH}/hello.txt
,flag: 'a+'})const res = fs.writeSync({fd: fd,data: 'some text'})console.log(res.bytesWritten)
This method is used via FileSystemManager.writeFile(Object object).
Attribute | Type | Default value | Required | Description |
filePath | string | - | Yes | Path of file to be written in. |
data | string/ArrayBuffer | - | Yes | The text or binary data to be written in. |
encoding | string | utf8 | No | Specifies the character encoding for the file to be written. |
success | function | - | No | Callback Function of Successful Interface Call |
fail | function | - | No | Callback Function of Failing Interface Call |
complete | function | - | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Value | Description |
ascii | - |
base64 | - |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
Attribute | Type | Description |
errMsg | string | Error Message |
Value | Description |
fail no such file or directory, open ${filePath} | The directory of the specified filePath does not exist. |
fail permission denied, open ${dirPath} | The specified filePath does not have write permissions. |
const fs = wx.getFileSystemManager()fs.writeFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text or arrayBuffer',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.writeFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`,'some text or arrayBuffer','utf8')console.log(res)} catch(e) {console.error(e)}
This method is used via FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding).
Value | Description |
ascii | - |
base64 | Note that if you choose base64 encoding, you only need to pass the base64 content itself as data, not the Data URI prefix, otherwise you will get a fail base64 encode error. For example, pass aGVsbG8= instead of data:image/png;base64,aGVsbG8=. |
binary | - |
hex | - |
ucs2/ucs-2/utf16le/utf-16le | Reads in little-endian order. |
utf-8/utf8 | - |
latin1 | - |
const fs = wx.getFileSystemManager()fs.writeFile({filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,data: 'some text or arrayBuffer',encoding: 'utf8',success(res) {console.log(res)},fail(res) {console.error(res)}})// Synchronization interfacetry {const res = fs.writeFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`,'some text or arrayBuffer','utf8')console.log(res)} catch(e) {console.error(e)}
Error code | Error Message | Description |
1300001 | operation not permitted | Operation not permitted (for instance, filePath is expected to receive a file but a directory is actually passed in). |
1300002 | no such file or directory ${path} | The file/directory does not exist, or the parent directory of the target file path does not exist. |
1300005 | Input/output error | Input/output stream is unavailable. |
1300009 | bad file descriptor | Invalid file descriptor. |
1300013 | permission denied | Permission error. The file is read-only or write-only. |
1300014 | Path permission denied | The specified path does not have permissions. |
1300020 | not a directory | The specified dirPath is not a directory, a case commonly seen when the parent path of the designated write path is a file. |
1300021 | Is a directory | The specified path is a directory. |
1300022 | Invalid argument | Invalid parameters. Consider checking if length or offset has exceeded their limits. |
1300036 | File name too long | File name is too long. |
1300066 | directory not empty | The directory is not empty. |
1300201 | system error | The system interface call has failed. |
1300202 | the maximum size of the file storage limit is exceeded | Insufficient storage space, or the file size has exceeded the limit (maximum 100 M). |
1300203 | base64 encode error | Character encoding conversion has failed (for instance, base64 format error). |
1300300 | sdcard not mounted | Android SD card mounting has failed. |
1300301 | unable to open as fileType | Unable to open the file with the specified fileType. |
1301000 | permission denied, cannot access file path | No access permission to the target path (usr directory). |
1301002 | data to write is empty | The data written in is empty. |
1301003 | illegal operation on a directory | This operation cannot be performed on a directory (for example, the specified filePath is an existing directory). |
1301004 | illegal operation on a package directory | This operation cannot be performed on the code package directory. |
1301005 | file already exists ${dirPath} | A file or directory with the same name already exists. |
1301006 | value of length is out of range | The length passed in is invalid. |
1301007 | value of offset is out of range | The offset passed in is invalid. |
1301009 | value of position is out of range | The position value is out of limits. |
1301100 | store directory is empty | The "store" directory is empty. |
1301102 | unzip open file fail | Failed to open the compressed file. |
1301103 | unzip entry fail | De-compression of individual files failed. |
1301104 | unzip fail | De-compression failed. |
1301111 | brotli decompress fail | Brotli de-compression failed (for instance, the specified compression algorithm does not match the actual compression format of the file). |
1301112 | tempFilePath file not exist | The file is not found in the specified tempFilePath. |
1302001 | fail permission denied | The specified fd path does not have read/write permissions. |
1302002 | excced max concurrent fd limit | The number of file descriptors has reached its maximum limit. |
1302003 | invalid flag | Invalid flag. |
1302004 | permission denied when open using flag | Unable to open the file using the flag indicator. |
1302005 | array buffer does not exist | ArrayBuffer has not been passed in. |
1302100 | array buffer is readonly | The ArrayBuffer is read-only. |
This method is used via boolean Stats.isDirectory().
This method is used via boolean Stats.isFile().
Was this page helpful?