我目前正在用 javascript 开发一个应用程序,我想使用 cordova 或 phonegap 来使我的代码适应 android、Iphone 等。但是在我的应用程序中,我用这个函数保存了我的文件:
function save(){
var myFileJSON = JSON.stringify(myFile);
try{
var blob = new Blob([myFileJSON], {type: "text/plain;charset=utf-8"});
saveAs(blob, "myFileJSON.txt");
} catch (e){
console.log('bug');
}
}
所以对于我的手机应用程序,我想将我的文件保存在一个特定的文件夹中。我可以捕获保存事件并立即重定向路径吗?
最佳答案
function saveCourseToFile() {
console.log("checkpoint 1");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, onFSError);
}
function onFSSuccess(fileSystem) {
console.log("checkpoint 2");
console.log("Opened file system: " + fileSystem.name);
fileSystem.root.getFile("readme.txt", {create:true, exclusive:false}, gotFileEntry, onFSError);
}
function gotFileEntry(fileEntry) {
console.log("checkpoint 3");
fileEntry.createWriter(gotFileWriter, onFSError);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("checkpoint 4: write success!");
};
writer.write("test test test");
}
您还可以检查this供您引用的链接。
关于javascript - Cordova 或 phonegap : saving file catcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34988204/