Skip to content
wuzhun.wz edited this page Jun 12, 2018 · 1 revision

FILE 模块说明

FILE

API
参数说明
使用注意
FILE.issupport()
功能: 查询是否支持FILE文件系统操作接口。
参数:无
返回值:1,支持
0,不支持
在使用FILE文件操作前,建议先使用FILE.issupport操作,对于嵌入式操作系统,某些可能不支持该接口。
FILE.read(filepath)
功能:读取文件内容
参数:文件完整路径
返回值:读取失败返回空字符串,读取成功返回读取的文件内容
FILE.delete(filepath)
功能:删除文件
参数:文件完整路径
返回值:0 删除成功
其他 删除文件失败
FILE.write(filepath,buffer,mode)
功能:往指定文件写入指定buffer的内容。
参数:filepath 文件路径
buffer 待写入的文件缓冲区。
mode 写入的文件模式。
返回值:0写文件成功
其他,写文件失败
mode可以为
"w","r","w+","r+","a","a+"
类似与fopen(const char * restrict path, const char * restrict mode)的参数mode。
FILE.rename(filepath)
功能:重命名一个文件
参数:文件路径
返回值: 0 操作成功
其他,操作失败。

js测试程序示例:

var fsenable = FS.issupport();
console.log('FS enable '+fsenable);
var writefile = 'test FS write buffer:hello world';
var ret = FS.write('/spiffs/hello.js',writefile,'w+');
console.log('FS.write+'+ret);
var ret = FS.read('/spiffs/hello.js');
console.log('FS read hello.js ='+ ret);
var ret = FS.rename('/spiffs/hello.js','/spiffs/hello1.js');
console.log('FS rename ='+ ret);
var ret = FS.read('/spiffs/hello1.js');
console.log('FS read hello1.js='+ ret);
var ret = FS.delete('/spiffs/hello1.js');
console.log('FS delete ='+ ret);

示例运行log如下:

BoneEngine > FS enable 1 
FS.write(/spiffs/hello.js,test FS write buffer:hello world,w+);
BoneEngine > FS.write+0 
BoneEngine > FS read hello.js =test FS write buffer:hello world 
BoneEngine > FS rename =0 
BoneEngine > FS read hello1.js=test FS write buffer:hello world 
BoneEngine > FS delete =0 

Clone this wiki locally