Assets相关
javascript
//Node版引擎导入方式
import core from 'cheese-node';
//JS版引擎导入方式
const core = require('cheese-js');
读取文件或文件夹: public static read(path: string): string
✅
参数:
- ⭐
string
(path): 路径
返回值:
- 🟢
string
: 文件内容 or 文件列表 - 🔴null
用法示例:
javascript
const assets = core.assets;
const fileContent = assets.read("ww/test.txt");
console.log("文件内容", fileContent);
拷贝文件或文件夹: public static copy(path: string, destPath: string): boolean
✅
参数:
- ⭐
string
(path): 文件或文件夹路径 - ⭐
string
(destPath): 目标路径
返回值:
- 🟢
boolean
: true - 🔴
boolean
: false
用法示例:
javascript
const assets = core.assets;
if (assets.copy("ww/test.txt", "/storage/emulated/0/t.txt")) {
console.log("复制成功");
}
判断路径是不是文件夹: public static isFolder(path: string): boolean
✅
参数:
- ⭐
string
(path): 路径
返回值:
- 🟢
boolean
: true - 🔴
boolean
: false
用法示例:
javascript
const assets = core.assets;
if (assets.isFolder("ww")) {
console.log("是文件夹");
}
判断路径是不是文件: public static isFile(path: string): boolean
✅
参数:
- ⭐
string
(path): 路径
返回值:
- 🟢
boolean
: true - 🔴
boolean
: false
用法示例:
javascript
const assets = core.assets;
if (assets.isFile("ww/test.txt")) {
console.log("是文件");
}