gpt4 book ai didi

html - Phonegap 文件编写器不工作,无法截断文件内容

转载 作者:行者123 更新时间:2023-11-27 22:37:41 24 4
gpt4 key购买 nike

我正在使用 phonegap 文件读取功能,一旦我读取了内容,我将对该内容执行一些功能,一旦完成,我将调用文件截断功能。因为我不能截断任何值。帮我解决这个问题。

removeFileContent();

function removeFileContent(){
console.log("Inside remove file content");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileTruncate, onProcessFailure);
};

function gotFileTruncate(fileSystem){
console.log("Inside get file path for remove content");
/** Function to get file path */
filePath = getFilePath(device.platform);
console.log("Device File Path to remove content-->"+this.filePath);
fileSystem.root.getFile(filePath, null, gotFileEntryTruncate, onProcessFailure);
}

function gotFileEntryTruncate(fileEntry){
globals.raiseLog("Inside file to truncate call");
globals.raiseLog("File Name-->"+fileEntry.name);
fileEntry.createWriter(gotFileWriter, onProcessFailure);
}

function gotFileWriter(writer){
globals.raiseLog("Inside file writer to truncate file content");
globals.raiseLog("Content length-->"+writer.length);
//writer.truncate(10);
writer.onwriteend = function(evt) {
writer.truncate(0);
writer.onwriteend = function(evt) {
};
};
writer.write("");
globals.raiseLog("Content length after truncate-->"+writer.length);
}

在上面的 gotFileWriter() 中,如果我检查 writer.length 它仍然显示一些计数。我不知道我们怎么可以检查文件变空了。我在该文件中有一些文本。当我完成文件读取时需要清除文件。完成阅读功能后,我正在调用 removeFileContent() 。请帮忙。

最佳答案

您编写代码的方式可能会误报文件中仍有内容。移动你的:

globals.raiseLog("Content length after truncate-->"+writer.length);

进入您的 onwriteend 函数,因为写入调用是异步的,并且在打印日志之前可能无法完成。

关于html - Phonegap 文件编写器不工作,无法截断文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12975451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com