我正在嘗試File.writefile使用 Ionic Native,但我遇到了天氣引數的問題。
這是檔案的鏈接 - https://ionicframework.com/docs/v3/native/file/
File.writeFile('file:///storage/emulated/0/Documents/', 'result.txt', `testing123\n`, {append: true}).then(succ=>{
alert("File write success : " JSON.stringify(succ))
},
err=>{
alert(" write File error : " JSON.stringify(err))
});
當我使用{replace: true}它時,它每次都會寫入一個新檔案,但不會追加資料。
如果我使用{append: true},那么它不會在檔案運行時創建檔案......它必須存在。
如果它不存在并附加到它,我如何讓它創建一個檔案?
uj5u.com熱心網友回復:
作為一種解決方法,捕獲錯誤,創建檔案并呼叫您的函式。
也可以使用await,因為它增加了可讀性。
await File.writeFile('file:///storage/emulated/0/Documents/', 'result.txt', `testing123\n`, {append: true}).catch (e) {
await File.writeFile('file:///storage/emulated/0/Documents/', 'result.txt', `testing123\n`, {append: false});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/460327.html
上一篇:如何將InAppBrowser添加到Spec檔案以停止錯誤?
下一篇:物件鍵值為空但有資料
