首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JavaScript:从事后效果编写和附加文本文件

JavaScript:从事后效果编写和附加文本文件
EN

Stack Overflow用户
提问于 2017-06-02 20:18:08
回答 1查看 3.7K关注 0票数 0

检查txt文件是否已经存在。如果它存在,我想打开并追加。如果!存在,我想创造,打开,写。我不知道该怎么附加文件..。

到目前为止,这是我的代码:

代码语言:javascript
复制
function writeReport(path, reportText) {

    var reportFile = new File(path  + "/font_report.txt");

    if(reportFile.exists){
        alert('file already exists');

        reportFile.open("w");
        reportFile.write(reportText);
        reportFile.close();
    }
    else{

        var RCF_file = new File(reportFile);
        RCF_file.open("w");
        RCF_file.write(reportText);
        RCF_file.close();

    }
    alert('Report Complete');
}

if(现有)中的代码显然与其他{}中的代码相同--不确定它应该是什么.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-02 20:49:03

为了附加文件,它需要通过附加模式.

代码语言:javascript
复制
reportFile.open("a");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44336836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档