收藏
回答

writeFileSync写二进制数据到文件中,数据不能大于0x80?

const logfilepath = `${wx.env.USER_DATA_PATH}/LogData.txt`

App({

  onLaunch() {

    let that = this

    if (that.onAccessFile11(logfilepath)) {

      try {

        wx.getFileSystemManager().unlinkSync(logfilepath);

      } catch (error) {

        console.log('onDeleteFile,删除文件异常' + error);

      }

    } else {

      console.log('onDeleteFile,文件不存在');

    }

    let buffer = new ArrayBuffer(300)

    let dataView = new DataView(buffer)

    for (let i = 0; i < 300; i++) {

      dataView.setUint8(i, i)

    }

    console.log(buffer)

    try {

      wx.getFileSystemManager().writeFileSync(logfilepath, buffer, 'binary')

      console.log('保存到文件中OK');

    } catch (error) {

      console.log('保存到文件中出错' + error);

    }

    wx.login({

      success: res => {

        // 发送 res.code 到后台换取 openId, sessionKey, unionId

        console.log('login=' + JSON.stringify(res))

      }

    })

  },

  onAccessFile11: function (filepath) {

    try {

      wx.getFileSystemManager().accessSync(filepath);

      return true

    } catch (error) {

      return false

    }

  },

})

最后一次编辑于  2021-03-21
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签