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);
    }
    );
    }

  • 相关阅读:
    ElasticSearch学习记录
    用java代码手动控制kafkaconsumer偏移量
    kafka0.9.0及0.10.0配置属性
    kafka常用命令
    kafka消费者客户端(0.9.0.1API)
    kafka入门教程链接
    编程内功
    bzoj3145:[Feyat cup 1.5]Str
    3 SpringBoot与微服务
    2 微服务存在的问题和解决方案
  • 原文地址:https://www.cnblogs.com/peipeiyu/p/9757515.html
Copyright © 2011-2022 走看看