字符串路径
字符串路径被解释为标识绝对或相对文件名的 UTF-8 字符序列。
相对路径将相对于通过调用 process.cwd()
确定的当前工作目录进行解析。
在 POSIX 上使用绝对路径的示例:
import { open } from 'node:fs/promises';
let fd;
try {
fd = await open('/open/some/file.txt', 'r');
// 对文件做一些事情
} finally {
await fd.close();
}
在 POSIX 上使用相对路径的示例(相对于 process.cwd()
):
import { open } from 'node:fs/promises';
let fd;
try {
fd = await open('file.txt', 'r');
// 对文件做一些事情
} finally {
await fd.close();
}
String paths are interpreted as UTF-8 character sequences identifying
the absolute or relative filename. Relative paths will be resolved relative
to the current working directory as determined by calling process.cwd()
.
Example using an absolute path on POSIX:
import { open } from 'node:fs/promises';
let fd;
try {
fd = await open('/open/some/file.txt', 'r');
// Do something with the file
} finally {
await fd.close();
}
Example using a relative path on POSIX (relative to process.cwd()
):
import { open } from 'node:fs/promises';
let fd;
try {
fd = await open('file.txt', 'r');
// Do something with the file
} finally {
await fd.close();
}