zoukankan      html  css  js  c++  java
  • 写入文件(覆盖文件的内容)

    function saveEltValuestoFile(that,signleList){
    //eltid是用来给文件命名的关键字
    plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS,
    function(fs){
    //fs.root 是根目录操作对象
    fs.root.getFile("msg/"+userid+".txt",{create:true}, function(fileEntry){
    fileEntry.file(function(file){
    //写入文件
    fileEntry.createWriter(
    function(writer){
    writer.onwrite = function(e){
    console.log(e);
    console.log(JSON.stringify(e));
    console.log("写入数据成功");
    }
    writer.write(JSON.stringify(signleList));
    $(that).parent().parent().remove();
    },
    function(error){
    console.log("创建Writer失败" + error.message);
    });
    /////读取文件
    var fileReader =new plus.io.FileReader();
    console.log("getFile:" + JSON.stringify(file));
    fileReader.readAsText(file,'utf-8');
    fileReader.onloadend = function(evt){
    console.log("msg/"+userid+".txt"+JSON.stringify(evt));
    console.log("evt.target" + JSON.stringify(evt.target));
    console.log("evt.target.result" + JSON.stringify(evt.target.result));
    console.log(JSON.parse(evt.target.result));
    }
    });
    },
    function(err){
    console.log("访问File失败"+ err.message);
    }
    )
    },
    function(error){
    console.log("访问_DOC目录失败"+ error.message);
    }
    );
    }

  • 相关阅读:
    次小生成树
    [bzoj5329] P4606 [SDOI2018]战略游戏
    CF487E Tourists
    P3225 [HNOI2012]矿场搭建
    CF #636 (Div. 3) 对应题号CF1343
    P3469 [POI2008]BLO-Blockade
    大假期集训模拟赛12
    大假期集训模拟赛11
    大假期集训模拟赛10
    小奇画画——BFS
  • 原文地址:https://www.cnblogs.com/peipeiyu/p/9757515.html
Copyright © 2011-2022 走看看