overwrite a file with HTML5 FileWriter

前端 未结 5 564
我寻月下人不归
我寻月下人不归 2021-01-01 22:30

I\'m using HTML5 FileWriter API to save the state of my webapp. I have bit of JS that periodically calls FileWriter.write to do that (so , over time, the

5条回答
  •  耶瑟儿~
    2021-01-01 23:01

    You can truncate and then write with two different FileWriter objects.

    fileEntry.createWriter(function (fileWriter) {
    
            fileWriter.truncate(0);
    
        }, errorHandler);
    
    fileEntry.createWriter(function (fileWriter) {
    
            var blob = new Blob(["New text"], { type: 'text/plain' });
    
            fileWriter.write(blob);
    
        }, errorHandler);
    

提交回复
热议问题