# 文件 File

JSKit App 提供了文件模块 file,导出了三个类:FileFileReaderFileWriter

# File

class File {
    constructor(path: string);
    list(): string[];
    isDirectory(): boolean;
    isFile(): boolean;
    isHidden(): string;
    getName(): string;
    getPath(): string;
    exists(): boolean;
    delete(): boolean;
    createNewFile(): boolean;
    getParent(): string;
    getCanonicalPath(): string;
    copyTo(file: File): void;
}

# FileReader

class FileReader {
    constructor(file: File);
    readBytes(): ArrayBuffer;
    readString(): string;
    readLine(): string;
    close(): void;
}

# FileWriter

class FileWriter {
    constructor(file: File);
    writeBytes(bytes: ArrayBuffer): void;
    writeString(str: string);
    close(): void;
}

注意

  • JSkit APP 只允许访问自己的私有目录,一般为:/sdcard/Android/data/com.jskitapp.jskit/files/*
  • FileReader 和 FileWriter 两个都是一次性的,有状态的类。如 readLine() 每次都会读取一行,直到读取至文件末尾。使用完毕后,应该调用 close() 关闭。
  • 现在的 file 接口都是同步接口。请勿在主线程读写大文件,如果需要,可在 Worker 线程进行操作。