大佬教程收集整理的这篇文章主要介绍了cordova – 如何删除phonegap中的文本文件内容?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果你之后要写,那会更复杂一些.你不能只是
writer.truncate(0); writer.write("Leo was here");
如果你这样做似乎既不起作用,但每个人都单独工作.因此,为了使其工作,您必须等到截断完成后才能执行写操作.在截断的onwriteend中添加写入.注意清除或更改onwwriteend很重要,否则你将获得无限循环.
function clearFile(fileName){ window.requestFileSystem(LocalFileSystem.PERSISTENT,function(fileSystem){ fileSystem.root.getFile(filename,{ create: false },clearfileExists,fileDoesnotExist); },getFSFail); }
function clearfileExists(fileEntry){ console.log("File " + fileEntry.fullPath + " exists!"); fileEntry.createWriter(truncateFile,fileDoesnotExist); }
现在你有了一个文件编写器.调用truncate(0)并在onwriteend中清除onwrite结束并写下你想要的内容.
function truncateFile(writer){ console.log("truncate"); writer.onwriteend= function(evt) { LOG("write"); writer.seek(0); writer.onwriteend = function(evt){ console.log("contents of file Now 'Leo was Here'"); } writer.write("Leo was Here"); } writer.truncate(0); }
并且为了完整性,这里是错误案例的处理
function fileDoesnotExist(){ console.log("file does not exist"); } function getFSFail(evt) { console.log(evt.target.error.codE); }
以上是大佬教程为你收集整理的cordova – 如何删除phonegap中的文本文件内容?全部内容,希望文章能够帮你解决cordova – 如何删除phonegap中的文本文件内容?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。