文档有命名空间fileUtils,但不会用,不会写数据到一个文件中

比如 想将一个字符串写到D盘
import { _decorator, Component, native} from ‘cc’;

const { fileUtils } = native;

const { ccclass, property } = _decorator;

@ccclass(‘NewComponent_001’)

export class NewComponent_001 extends Component {

start() {

        let str:string="ddd";

        fileUtils.writeStringToFile(str,"D:/lll.txt")

}

update(deltaTime: number) {

}

}
写不进去啊

这个代码已经挂在节点上了,就是不能写文件进去

这样试试 jsb.fileUtils.writeStringToFile

jsb打上去就报错啊

[{
“resource”: “/F:/lwj/NewProject_2/assets/NewComponent.ts”,
“owner”: “typescript”,
“code”: “2339”,
“severity”: 8,
“message”: “类型“typeof jsb”上不存在属性“fileUtils”。”,
“source”: “ts”,
“startLineNumber”: 16,
“startColumn”: 13,
“endLineNumber”: 16,
“endColumn”: 22
}]

“typeof jsb”上不存在属性“fileUtils”。”,

原生上才能写入

start() {

    let str:string="ddd";

if(NATIVE){

    native.fileUtils.writeStringToFile(str,"D:/lll.txt")

}

}
我这样试了,也不行啊

ios android windows 才能用 说白了就是 sys.isNative为true才行

那如果要读写一个文件,用什么读写呢

浏览器只能触发用户下载 读取也只能是loadremote 还有构建后的资源最多也就还能接受用户拖入的文件

你是构建到什么平台

我是用cocos creator写一个游戏,准备发布到安卓或者微信小游戏

想一些数据到本地的JSON文件里。
你刚说的loadremote 是远程加载资源啊

不想用localStorage这个,听说比较慢,我要写的数据量比较大

安卓fileutils那个能用,微信小游戏嘛找找微信的api可能会有

fileutils 我在电脑上试的 不起作用啊

你要构建打包了才能有效果呀

我是想提前写一个JSON文件,数据都在里面,其他文件可以调用,数据量比较大

那你第一次打开应用的时候就用writeStringToFile写呀