Skip to content

Assets相关

javascript
const core = require('cheese-js');
lua
local core = require('cheese-lua')

读取文件或文件夹: 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);
lua
local assets = core.assets
local fileContent = assets.read("ww/test.txt")
print("文件内容", 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("复制成功");
}
lua
local assets = core.assets
if assets.copy("ww/test.txt", "/storage/emulated/0/t.txt") then
    print("复制成功")
end

判断路径是不是文件夹: public static isFolder(path: string): boolean

参数:

  • string (path): 路径

返回值:

  • 🟢boolean: true
  • 🔴boolean: false

用法示例:

javascript
const assets = core.assets;
if (assets.isFolder("ww")) {
    console.log("是文件夹");
}
lua
local assets = core.assets
if assets.isFolder("ww") then
    print("是文件夹")
end

判断路径是不是文件: 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("是文件");
}
lua
local assets = core.assets
if assets.isFile("ww/test.txt") then
    print("是文件")
end

Released under the GPL-3.0 License.