import { writeFile, appendFile, readFile } from 'node:fs/promises'; /** *! writeFile 写 */ export async function writeFileAsync() { try { await writeFile('./log.txt', 'heheda'); console.log('写入成功'); } catch (error) { console.error('写入失败:', error); } } /** *! appendFile 向文件末尾追加内容 */ export async function appendFileAsync(data = '') { try { await appendFile('./log.append.txt', data); console.log('写入成功'); } catch (error) { console.error('写入失败:', error); } } /** *! readFile 读取文件内容 */ export async function readFileAsync() { try { // 默认读取的内容 是 二进制数据的16进制编码 数据 // let content = await readFile('./log.append.txt'); let content = await readFile('./log.append.txt', 'utf8'); console.log(content); } catch (error) {} }