Deno.opensync
openSync
-
openSync(path: string, options?: OpenOptions): File
-
用同步方式打开一个文件并返回一个
Deno.File
实例。如果使用了create
或createNew
配置项 文件可以不需要预先存在。调用者应该在完成后关闭文件。Synchronously open a file and return 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 = Deno.openSync("/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)
返回 File
-
用同步方式打开一个文件并返回一个
Deno.File
实例。根据传入的模式,可以创建文件。 调用者应该在完成后关闭文件。Synchronously open a file and return 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 = Deno.openSync("/foo/bar.txt", "r"); // 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)