Deno.open
open
-
open(path: string, options?: OpenOptions): Promise<File>
-
打开一个文件并异步返回一个
Deno.File
实例。如果使用了create
或createNew
配置项 文件可以不需要预先存在。调用者应该在完成后关闭文件。Open a file and resolve to an instance of
Deno.File
. The file does not need to previously exist if using thecreate
orcreateNew
open options. It is the callers responsibility to close the file when finished with it.const file = await Deno.open("/foo/bar.txt", { read: true, write: true }); // Do work with file Deno.close(file.rid);
根据不同的选项需要相应的
allow-read
及allow-write
权限。Requires
allow-read
and/orallow-write
permissions depending on options.
参数
- ##### path: string
- ##### Optional options: [OpenOptions](interfaces/deno.openoptions.html)
返回 Promise<File>
-
打开一个文件并异步返回一个
Deno.File
实例。根据传入的模式,可以创建文件。 调用者应该在完成后关闭文件。Open a file and resolve to an instance of
Deno.File
. The file may be created depending on the mode passed in. It is the callers responsibility to close the file when finished with it.const file = await Deno.open("/foo/bar.txt", "w+"); // Do work with file Deno.close(file.rid);
根据不同的打开模式需要相应的
allow-read
及allow-write
权限。Requires
allow-read
and/orallow-write
permissions depending on openMode.
参数
- ##### path: string
- ##### Optional openMode: [OpenMode](index.html#openmode)