let applicationContext = getContext(this).getApplicationContext();
let pathDir = applicationContext.filesDir;
let filePath = pathDir + "/test.txt";
let dir = pathDir + "/temp1";
let stat = fs.statSync(filePath)
console.info("文件信息 " + stat.size + "---" + JSON.stringify(stat));
let stat1 = fs.lstatSync(filePath)
console.info("文件信息 " + stat.size + "---" + JSON.stringify(stat1));
let exists = fs.accessSync(filePath);
console.info("是否存在 " + exists);
let file = fs.openSync(filePath);
fs.closeSync(file);
let filePathNew = pathDir + "/test1.txt";
fs.copy(filePath, filePathNew, {
progressListener: (progress: fs.Progress) => {
console.info("进度 " + progress);
}
})
let filePathNew1 = pathDir + "/test2.txt";
fs.copy(filePath, filePathNew1, (error) => {
if (error) {
console.info("copy 失败" + error.code);
} else {
console.info("copy 成功");
}
})
let filePathNew2 = pathDir + "/test3.txt";
fs.copyFileSync(filePath, filePathNew2)
fs.copyDirSync(filePath, filePathNew2, 1)
let filePath1 = pathDir + "/test.txt";
let file1 = fs.openSync(filePath1, fs.OpenMode.READ_WRITE);
let fd: number = file1.fd;
let file2 = fs.dup(fd);
console.info("The name of the file2 is " + file2.name);
fs.closeSync(file1);
fs.closeSync(file2);
fs.mkdirSync(dir)
fs.mkdirSync(dir, true)
let filePath4 = pathDir + "/test.txt";
let fileNew: fs.File = fs.openSync(filePath4, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE)
let buffer = new ArrayBuffer(1024)
fs.readSync(fileNew.fd, buffer, { offset: 1, length: 1000 })
fs.rmdirSync('')
fs.unlinkSync('')
fs.writeSync(1, '1111111')
fs.readLinesSync('')
read() {
let applicationContext = getContext(this).getApplicationContext();
let pathDir = applicationContext.filesDir;
let filePath = pathDir + "/test.txt";
let options: Options = {
encoding: 'utf-8'
};
fs.readLines(filePath, options).then((readerIterator: fs.ReaderIterator) => {
for (let it = readerIterator.next();!it.done; it = readerIterator.next()) {
console.info("content: " + it.value);
}
}).catch((err: BusinessError) => {
console.error("readLines failed with error message: " + err.message + ", error code: " + err.code);
});
fs.readTextSync('')
fs.renameSync("old", "new")
let filePath11 = pathDir + "/test.txt";
let file = fs.openSync(filePath11);
fs.fsyncSync(file.fd);
fs.closeSync(file);
let filePath2 = pathDir + "/test.txt";
let file2 = fs.openSync(filePath2);
fs.fdatasyncSync(file2.fd);
fs.closeSync(file);
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + "/test";
fs.symlinkSync(srcFile, dstFile);
let listFileOption: ListFileOptions = {
recursion: false,
listNum: 0,
filter: {
suffix: [".png", ".jpg", ".jpeg"],
displayName: ["*abc", "efg*"],
fileSizeOver: 1024
}
};
let filenames = fs.listFileSync('', listFileOption)
for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]);
}
fs.moveDirSync("srcPath", "destPath", 1);
fs.moveFileSync('', '')
fs.mkdtempSync('')
let filePath111 = pathDir + "/test.txt";
let file111 = fs.openSync(filePath111, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
fs.createRandomAccessFileSync(file111)
let stream = fs.createStreamSync('', 'r')
stream.closeSync();
let filePathfdop = pathDir + "/test.txt";
let filefdop = fs.openSync(filePathfdop);
let stream2 = fs.fdopenStreamSync(filefdop.fd, "r+")
stream2.closeSync()
fs.createWatcher('path', 0x4, (event: WatchEvent) => {
})
let isDirectory = fs.statSync("dirPath").isDirectory();
let isFile = fs.statSync("dirPath").isFile();
let fileNew = fs.openSync("path");
fs.closeSync(fileNew);
fileNew.getParent()
}