mac版开发工具,无法读取本地文件,提示no such file,该如何解决?
发布于 7 年前 作者 juan20 14389 次浏览 来自 问答
onLoad: function () {

    wx.getFileSystemManager().copyFile({ //先把文件复制到可操作的文件夹
      srcPath: '../data.json', //源文件
      destPath: wx.env.USER_DATA_PATH + '/data.json', //可操作的4文件夹路径
      success: res => {
        console.log(res) //复制成功返回res信息
      },
      fail: console.error //复制失败返回error
    }),

    wx.getFileSystemManager().readFile({ //读取文件
      filePath:  'data.json',
      encoding: 'utf-8',
      encoding: 'utf-8',
      success: res => {
        console.log(res.data)
      },
      fail: console.error
    })
  }
}
文件名试过  data.json 或者  ..\data.json 都不行。

回到顶部