filehandle.close()


  • 返回:<Promise> 成功时返回 undefined

在等待与该句柄相关的任何待处理操作完成后关闭文件句柄。

【Closes the file handle after waiting for any pending operation on the handle to complete.】

import { open } from 'node:fs/promises';

let filehandle;
try {
  filehandle = await open('thefile.txt', 'r');
} finally {
  await filehandle?.close();
}