微信小程序API 文件·文件管理器

2022-05-11 16:48 更新

FileSystemManager

基礎(chǔ)庫 1.9.9 開始支持,低版本需做兼容處理。

文件管理器


方法:

FileSystemManager.access(Object object)

判斷文件/目錄是否存在

參數(shù)

Object object

屬性 類型 默認值 必填 說明
path string 要判斷是否存在的文件/目錄路徑 (本地路徑)
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory ${path} 文件/目錄不存在



FileSystemManager.accessSync(string path)

FileSystemManager.access 的同步版本

參數(shù)

string path

要判斷是否存在的文件/目錄路徑 (本地路徑)

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory ${path} 文件/目錄不存在


FileSystemManager.appendFile(Object object)

基礎(chǔ)庫 2.1.0 開始支持,低版本需做兼容處理。

在文件結(jié)尾追加內(nèi)容

參數(shù)

Object object

屬性 類型 默認值 必填 說明
filePath string 要追加內(nèi)容的文件路徑 (本地路徑)
data string/ArrayBuffer 要追加的文本或二進制數(shù)據(jù)
encoding string utf8 指定寫入文件的字符編碼
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.encoding 的合法值

說明 最低版本
ascii
base64
binary
hex
ucs2 以小端序讀取
ucs-2 以小端序讀取
utf16le 以小端序讀取
utf-16le 以小端序讀取
utf-8
utf8
latin1

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory, open ${filePath} 指定的 filePath 文件不存在
fail illegal operation on a directory, open "${filePath}" 指定的 filePath 是一個已經(jīng)存在的目錄
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail sdcard not mounted 指定的 filePath 是一個已經(jīng)存在的目錄


FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding)

基礎(chǔ)庫 2.1.0 開始支持,低版本需做兼容處理。

FileSystemManager.appendFile 的同步版本

參數(shù)

string filePath

要追加內(nèi)容的文件路徑 (本地路徑)

string|ArrayBuffer data

要追加的文本或二進制數(shù)據(jù)

string encoding

指定寫入文件的字符編碼

encoding 的合法值

說明 最低版本
ascii
base64
binary
hex
ucs2 以小端序讀取
ucs-2 以小端序讀取
utf16le 以小端序讀取
utf-16le 以小端序讀取
utf-8
utf8
latin1

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory, open ${filePath} 指定的 filePath 文件不存在
fail illegal operation on a directory, open "${filePath}" 指定的 filePath 是一個已經(jīng)存在的目錄
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail sdcard not mounted 指定的 filePath 是一個已經(jīng)存在的目錄


FileSystemManager.copyFile(Object object)

復(fù)制文件

參數(shù)

Object object

屬性 類型 默認值 必填 說明
srcPath string 源文件路徑,支持本地路徑
destPath string 目標文件路徑,支持本地路徑
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail permission denied, copyFile ${srcPath} -> ${destPath} 指定目標文件路徑?jīng)]有寫權(quán)限
fail no such file or directory, copyFile ${srcPath} -> ${destPath} 源文件不存在,或目標文件路徑的上層目錄不存在
fail the maximum size of the file storage limit is exceeded 存儲空間不足


FileSystemManager.copyFileSync(string srcPath, string destPath)

FileSystemManager.copyFile 的同步版本

參數(shù)

string srcPath

源文件路徑,支持本地路徑

string destPath

目標文件路徑,支持本地路徑

錯誤

錯誤碼 錯誤信息 說明
fail permission denied, copyFile ${srcPath} -> ${destPath} 指定目標文件路徑?jīng)]有寫權(quán)限
fail no such file or directory, copyFile ${srcPath} -> ${destPath} 源文件不存在,或目標文件路徑的上層目錄不存在
fail the maximum size of the file storage limit is exceeded 存儲空間不足


FileSystemManager.getFileInfo(Object object)

獲取該小程序下的 本地臨時文件 或 本地緩存文件 信息

參數(shù)

Object object

屬性 類型 默認值 必填 說明
filePath string 要讀取的文件路徑 (本地路徑)
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.success 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
size number 文件大小,以字節(jié)為單位

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail file not exist 指定的 filePath 找不到文件


FileSystemManager.getSavedFileList(Object object)

獲取該小程序下已保存的本地緩存文件列表

參數(shù)

Object object

屬性 類型 默認值 必填 說明
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.success 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
fileList Array.<Object> 文件數(shù)組

res.fileList 的結(jié)構(gòu)

屬性 類型 說明
filePath string 文件路徑 (本地路徑)
size number 本地文件大小,以字節(jié)為單位
createTime number 文件保存時的時間戳,從1970/01/01 08:00:00 到當前時間的秒數(shù)


FileSystemManager.mkdir(Object object)

創(chuàng)建目錄

參數(shù)

Object object

屬性 類型 默認值 必填 說明 最低版本
dirPath string 創(chuàng)建的目錄路徑 (本地路徑)
recursive boolean false 是否在遞歸創(chuàng)建該目錄的上級目錄后再創(chuàng)建該目錄。如果對應(yīng)的上級目錄已經(jīng)存在,則不創(chuàng)建該上級目錄。如 dirPath 為 a/b/c/d 且 recursive 為 true,將創(chuàng)建 a 目錄,再在 a 目錄下創(chuàng)建 b 目錄,以此類推直至創(chuàng)建 a/b/c 目錄下的 d 目錄。 2.3.0
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory ${dirPath} 上級目錄不存在
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail file already exists ${dirPath} 有同名文件或目錄


FileSystemManager.mkdirSync(string dirPath, boolean recursive)

FileSystemManager.mkdir 的同步版本

參數(shù)

string dirPath

創(chuàng)建的目錄路徑 (本地路徑)

boolean recursive

基礎(chǔ)庫 2.3.0 開始支持,低版本需做兼容處理。

是否在遞歸創(chuàng)建該目錄的上級目錄后再創(chuàng)建該目錄。如果對應(yīng)的上級目錄已經(jīng)存在,則不創(chuàng)建該上級目錄。如 dirPath 為 a/b/c/d 且 recursive 為 true,將創(chuàng)建 a 目錄,再在 a 目錄下創(chuàng)建 b 目錄,以此類推直至創(chuàng)建 a/b/c 目錄下的 d 目錄。

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory ${dirPath} 上級目錄不存在
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail file already exists ${dirPath} 有同名文件或目錄


FileSystemManager.readdir(Object object)

讀取目錄內(nèi)文件列表

參數(shù)

Object object

屬性 類型 默認值 必填 說明
dirPath string 要讀取的目錄路徑 (本地路徑)
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.success 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
files Array.<string> 指定目錄下的文件名數(shù)組。

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory ${dirPath} 目錄不存在
fail not a directory ${dirPath} dirPath 不是目錄
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有讀權(quán)限


Array.<string> FileSystemManager.readdirSync(string dirPath)

FileSystemManager.readdir 的同步版本

參數(shù)

string dirPath

要讀取的目錄路徑 (本地路徑)

返回值

Array.<string> files

指定目錄下的文件名數(shù)組。

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory ${dirPath} 目錄不存在
fail not a directory ${dirPath} dirPath 不是目錄
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有讀權(quán)限


FileSystemManager.readFile(Object object)

讀取本地文件內(nèi)容

參數(shù)

Object object

屬性 類型 默認值 必填 說明 最低版本
filePath string 要讀取的文件的路徑 (本地路徑)
encoding string 指定讀取文件的字符編碼,如果不傳 encoding,則以 ArrayBuffer 格式讀取文件的二進制內(nèi)容
position string 從文件指定位置開始讀,如果不指定,則從文件頭開始讀。讀取的范圍應(yīng)該是左閉右開區(qū)間 [position, position+length)。有效范圍:[0, fileLength - 1]。單位:byte 2.10.0
length string 指定文件的長度,如果不指定,則讀到文件末尾。有效范圍:[1, fileLength]。單位:byte 2.10.0
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.encoding 的合法值

說明 最低版本
ascii
base64
binary
hex
ucs2 以小端序讀取
ucs-2 以小端序讀取
utf16le 以小端序讀取
utf-16le 以小端序讀取
utf-8
utf8
latin1

object.success 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
data string/ArrayBuffer 文件內(nèi)容

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory, open ${filePath} 指定的 filePath 所在目錄不存在
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有讀權(quán)限


string|ArrayBuffer FileSystemManager.readFileSync(string filePath, string encoding, string position, string length)

FileSystemManager.readFile 的同步版本

參數(shù)

string filePath

要讀取的文件的路徑 (本地路徑)

string encoding

指定讀取文件的字符編碼,如果不傳 encoding,則以 ArrayBuffer 格式讀取文件的二進制內(nèi)容

encoding 的合法值

說明 最低版本
ascii
base64
binary
hex
ucs2 以小端序讀取
ucs-2 以小端序讀取
utf16le 以小端序讀取
utf-16le 以小端序讀取
utf-8
utf8
latin1

string position

基礎(chǔ)庫 2.10.0 開始支持,低版本需做兼容處理

從文件指定位置開始讀,如果不指定,則從文件頭開始讀。讀取的范圍應(yīng)該是左閉右開區(qū)間 [position, position+length)。有效范圍:[0, fileLength - 1]。單位:byte

string length

基礎(chǔ)庫 2.10.0 開始支持,低版本需做兼容處理

指定文件的長度,如果不指定,則讀到文件末尾。有效范圍:[1, fileLength]。單位:byte

返回值

string|ArrayBuffer data

文件內(nèi)容

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory, open ${filePath} 指定的 filePath 所在目錄不存在
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有讀權(quán)限


FileSystemManager.removeSavedFile(Object object)

刪除該小程序下已保存的本地緩存文件

參數(shù)

Object object

屬性 類型 默認值 必填 說明
filePath string 需要刪除的文件路徑 (本地路徑)
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail file not exist 指定的 tempFilePath 找不到文件


FileSystemManager.rename(Object object)

重命名文件??梢园盐募?oldPath 移動到 newPath

參數(shù)

Object object

屬性 類型 默認值 必填 說明
oldPath string 源文件路徑,支持本地路徑
newPath string 新文件路徑,支持本地路徑
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail permission denied, rename ${oldPath} -> ${newPath} 指定源文件或目標文件沒有寫權(quán)限
fail no such file or directory, rename ${oldPath} -> ${newPath} 源文件不存在,或目標文件路徑的上層目錄不存在


FileSystemManager.renameSync(string oldPath, string newPath)

FileSystemManager.rename 的同步版本

參數(shù)

string oldPath

源文件路徑,支持本地路徑

string newPath

新文件路徑,支持本地路徑

錯誤

錯誤碼 錯誤信息 說明
fail permission denied, rename ${oldPath} -> ${newPath} 指定源文件或目標文件沒有寫權(quán)限
fail no such file or directory, rename ${oldPath} -> ${newPath} 源文件不存在,或目標文件路徑的上層目錄不存在


FileSystemManager.rmdir(Object object)

刪除目錄

參數(shù)

Object object

屬性 類型 默認值 必填 說明 最低版本
dirPath string 要刪除的目錄路徑 (本地路徑)
recursive boolean false 是否遞歸刪除目錄。如果為 true,則刪除該目錄和該目錄下的所有子目錄以及文件。 2.3.0
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory ${dirPath} 目錄不存在
fail directory not empty 目錄不為空
fail permission denied, open ${dirPath} 指定的 dirPath 路徑?jīng)]有寫權(quán)限


FileSystemManager.rmdirSync(string dirPath, boolean recursive)

FileSystemManager.rmdir 的同步版本

參數(shù)

string dirPath

要刪除的目錄路徑 (本地路徑)

boolean recursive

基礎(chǔ)庫 2.3.0 開始支持,低版本需做兼容處理

是否遞歸刪除目錄。如果為 true,則刪除該目錄和該目錄下的所有子目錄以及文件。

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory ${dirPath} 目錄不存在
fail directory not empty 目錄不為空
fail permission denied, open ${dirPath} 指定的 dirPath 路徑?jīng)]有寫權(quán)限


FileSystemManager.saveFile(Object object)

保存臨時文件到本地。此接口會移動臨時文件,因此調(diào)用成功后,tempFilePath 將不可用。

參數(shù)

Object object

屬性 類型 默認值 必填 說明
tempFilePath string 臨時存儲文件路徑 (本地路徑)
filePath string 要存儲的文件路徑 (本地路徑)
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.success 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
savedFilePath string 存儲后的文件路徑 (本地路徑)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail tempFilePath file not exist 指定的 tempFilePath 找不到文件
fail permission denied, open "${filePath}" 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail no such file or directory "${dirPath}" 上級目錄不存在
fail the maximum size of the file storage limit is exceeded 存儲空間不足


string FileSystemManager.saveFileSync(string tempFilePath, string filePath)

FileSystemManager.saveFile 的同步版本

參數(shù)

string tempFilePath

臨時存儲文件路徑 (本地路徑)

string filePath

要存儲的文件路徑 (本地路徑)

返回值

string savedFilePath

存儲后的文件路徑 (本地路徑)

錯誤

錯誤碼 錯誤信息 說明
fail tempFilePath file not exist 指定的 tempFilePath 找不到文件
fail permission denied, open "${filePath}" 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail no such file or directory "${dirPath}" 上級目錄不存在
fail the maximum size of the file storage limit is exceeded 存儲空間不足


FileSystemManager.stat(Object object)

獲取文件 Stats 對象

參數(shù)

Object object

屬性 類型 默認值 必填 說明 最低版本
path string 文件/目錄路徑 (本地路徑)
recursive boolean false 是否遞歸獲取目錄下的每個文件的 Stats 信息 2.3.0
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.success 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
stats Stats/Object 當 recursive 為 false 時,res.stats 是一個 Stats 對象。當 recursive 為 true 且 path 是一個目錄的路徑時,res.stats 是一個 Object,key 以 path 為根路徑的相對路徑,value 是該路徑對應(yīng)的 Stats 對象。

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail permission denied, open ${path} 指定的 path 路徑?jīng)]有讀權(quán)限
fail no such file or directory ${path} 文件不存在

示例代碼

recursive 為 false 時


let fs = wx.getFileSystemManager()
fs.stat({
  path: `${wx.env.USER_DATA_PATH}/testDir`,
  success: res => {
    console.log(res.stats.isDirectory())
  }
})

recursive 為 true 時


fs.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())
    })
  }
})


Stats|Object FileSystemManager.statSync(string path, boolean recursive)

FileSystemManager.stat 的同步版本

參數(shù)

string path

文件/目錄路徑 (本地路徑)

boolean recursive

基礎(chǔ)庫 2.3.0 開始支持,低版本需做兼容處理。

是否遞歸獲取目錄下的每個文件的 Stats 信息

返回值

Stats|Object stats

當 recursive 為 false 時,res.stats 是一個 Stats 對象。當 recursive 為 true 且 path 是一個目錄的路徑時,res.stats 是一個 Object,key 以 path 為根路徑的相對路徑,value 是該路徑對應(yīng)的 Stats 對象。

錯誤

錯誤碼 錯誤信息 說明
fail permission denied, open ${path} 指定的 path 路徑?jīng)]有讀權(quán)限
fail no such file or directory ${path} 文件不存在

示例代碼

recursive 為 false 時


let fs = wx.getFileSystemManager()
fs.stat({
  path: `${wx.env.USER_DATA_PATH}/testDir`,
  success: res => {
    console.log(res.stats.isDirectory())
  }
})

recursive 為 true 時


fs.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())
    })
  }
})


FileSystemManager.unlink(Object object)

刪除文件

參數(shù)

Object object

屬性 類型 默認值 必填 說明
filePath string 要刪除的文件路徑 (本地路徑)
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值


說明 最低版本
fail permission denied, open ${path} 指定的 path 路徑?jīng)]有讀權(quán)限
fail no such file or directory ${path} 文件不存在
fail operation not permitted, unlink ${filePath} 傳入的 filePath 是一個目錄


FileSystemManager.unlinkSync(string filePath)

FileSystemManager.unlink 的同步版本

參數(shù)

string filePath

要刪除的文件路徑 (本地路徑)

錯誤

錯誤碼 錯誤信息 說明
fail permission denied, open ${path} 指定的 path 路徑?jīng)]有讀權(quán)限
fail no such file or directory ${path} 文件不存在
fail operation not permitted, unlink ${filePath} 傳入的 filePath 是一個目錄


FileSystemManager.unzip(Object object)

解壓文件

參數(shù)

Object object

屬性 類型 默認值 必填 說明
zipFilePath string 源文件路徑,支持本地路徑, 只可以是 zip 壓縮文件
targetPath string 目標目錄路徑, 支持本地路徑
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail permission denied, unzip ${zipFilePath} -> ${destPath} 指定目標文件路徑?jīng)]有寫權(quán)限
fail no such file or directory, unzip ${zipFilePath} -> "${destPath} 源文件不存在,或目標文件路徑的上層目錄不存在


FileSystemManager.writeFile(Object object)

寫文件

參數(shù)

Object object

屬性 類型 默認值 必填 說明
filePath string 要寫入的文件路徑 (本地路徑)
data string/ArrayBuffer 要寫入的文本或二進制數(shù)據(jù)
encoding string utf8 指定寫入文件的字符編碼
success function 接口調(diào)用成功的回調(diào)函數(shù)
fail function 接口調(diào)用失敗的回調(diào)函數(shù)
complete function 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

object.encoding 的合法值

說明 最低版本
ascii
base64
binary
hex
ucs2 以小端序讀取
ucs-2 以小端序讀取
utf16le 以小端序讀取
utf-16le 以小端序讀取
utf-8
utf8
latin1

object.fail 回調(diào)函數(shù)

參數(shù)
Object res
屬性 類型 說明
errMsg string 錯誤信息

res.errMsg 的合法值

說明 最低版本
fail no such file or directory, open ${filePath} 指定的 filePath 所在目錄不存在
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail the maximum size of the file storage limit is exceeded 存儲空間不足


FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding)

FileSystemManager.writeFile 的同步版本

參數(shù)

string filePath

要寫入的文件路徑 (本地路徑)

string|ArrayBuffer data

要寫入的文本或二進制數(shù)據(jù)

string encoding

指定寫入文件的字符編碼

encoding 的合法值

說明 最低版本
ascii
base64
binary
hex
ucs2 以小端序讀取
ucs-2 以小端序讀取
utf16le 以小端序讀取
utf-16le 以小端序讀取
utf-8
utf8
latin1

錯誤

錯誤碼 錯誤信息 說明
fail no such file or directory, open ${filePath} 指定的 filePath 所在目錄不存在
fail permission denied, open ${dirPath} 指定的 filePath 路徑?jīng)]有寫權(quán)限
fail the maximum size of the file storage limit is exceeded 存儲空間不足




以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號