2013-01-06 35 views
0

所以我卡住试图弄清楚这一点。阅读完成后,在FileSystem API中删除文件?

fileEntry.file(function(file){ 
    var reader = new FileReader(); 
    reader.onloadend = function (e) { 
    var anchor = document.createElement("a"); 
    anchor.setAttribute('href', "data:text/tsv;charset=UTF-8," + encodeURIComponent(this.result)); 
    anchor.setAttribute("download", "log.tsv"); 
    anchor.innerHTML = "Download Log Now"; 
    document.body.appendChild(anchor); 

    alert("Download by clicking the damn link at the bottom."); 

    //delete the file? 
    } 

    reader.readAsText(file); 
}); 

所以我的问题是如何在读取文件后删除文件?我已经尝试过在fileEntry.remove(function(){console.log("File Removed.")});的地方发表评论,但那是行不通的。

任何想法?

+0

一个.remove()接受一个错误回调作为第二个参数。错误消息说什么? – devio

+0

它什么也没说。这就像整个事情根本不能运行。 –

回答

0

你可以有承诺为基础bro-fs哪里,这是更干净一看:

fs.init() 
    .then(() => fs.readFile('file.txt')) 
    .then(content => console.log(content)) 
    .then(() => fs.unlink('file.txt')) 
相关问题