W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋:獲取文件 Stats 對(duì)象的同步接口。
Web 態(tài)說(shuō)明:受瀏覽器限制,Web 態(tài)不支持文件系統(tǒng)相關(guān)功能,調(diào)用該方法會(huì)拋出一個(gè)標(biāo)準(zhǔn)的 Error 對(duì)象。
返回參數(shù):String path
path
參數(shù)說(shuō)明:臨時(shí)存儲(chǔ)文件路徑。
返回值:Stats stats
stats 返回值說(shuō)明
若接口調(diào)用失敗,會(huì)拋出一個(gè)標(biāo)準(zhǔn)的Error
對(duì)象
<view class="wrap">
<button type="primary" bindtap="stat">獲取文件 Stats 對(duì)象</button>
</view>
Page({
data: {
filePath: ''
},
onLoad() {
this.fileSystemManager = swan.getFileSystemManager();
swan.downloadFile({
url: 'https://smartprogram.baidu.com/docs/img/logo.png',
success: res => {
swan.showToast({
title: `文件預(yù)下載完成,臨時(shí)路徑為${res.tempFilePath}`,
icon: 'none'
});
// 此為 “本地臨時(shí)文件” 路徑。
console.log(res.tempFilePath);
this.data.filePath = res.tempFilePath;
}
});
},
statSync() {
try {
let result = this.fileSystemManager.statSync(
this.data.filePath
// path: `${swan.env.USER_DATA_PATH}/demo.txt`,// 本地文件路徑
);
swan.showModal({
title: 'stat',
content: JSON.stringify(result)
});
console.log('statSync success', result);
}
catch (err) {
swan.showToast({
title: err + '',
icon: 'none'
});
console.log('statSync fail', err);
}
}
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: