openharmony 鸿蒙 js-apis-document

2025-06-12 浏览 (1)

@ohos.document (File Operation)

NOTE

  • The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs of this module have been deprecated since API version 9 and are not recommended for use. An exception will be thrown if any of the APIs is called.

Modules to Import

import document from '@ohos.document';

document.choose(deprecated)

choose(types?: string[]): Promise<string>

Chooses files of the specified types. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.UserFileService

Parameters

NameTypeMandatoryDescription
typesstring[]NoTypes of the files to choose.

Return value

TypeDescription
Promise<string>Promise used to return the result. An error code is returned.

Example

let types: Array<string> = [];
document.choose(types);

document.choose(deprecated)

choose(callback:AsyncCallback<string>): void

Chooses a file. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.FileManagement.UserFileService

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesCallback used to return the result. An error code is returned.

Example

let uri: string = "";
document.choose((err: TypeError, uri: string) => {
  // Do something with the URI. 
});

document.choose(deprecated)

choose(types:string[], callback:AsyncCallback<string>): void

Chooses files of the specified types. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.FileManagement.UserFileService

Parameters

NameTypeMandatoryDescription
typesstring[]YesTypes of the files to choose.
callbackAsyncCallback<string>YesCallback used to return the result. An error code is returned.

Example

let types: Array<string> = [];
let uri: string = "";
document.choose(types, (err: TypeError, uri: string) => {
  // Do something with the URI. 
});

document.show(deprecated)

show(uri:string, type:string):Promise<void>

Opens a file. This API uses a promise to return the result.

System capability: SystemCapability.FileManagement.UserFileService

Parameters

NameTypeMandatoryDescription
uristringYesURI of the file to open.
typestringYesType of the file to open.

Return value

TypeDescription
Promise<void>Promise used to return the result. An error code is returned.

Example

let type: string = "";
let uri: string = "";
document.show(uri, type);

document.show(deprecated)

show(uri:string, type:string, callback:AsyncCallback<void>): void

Opens a file. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.FileManagement.UserFileService

Parameters

NameTypeMandatoryDescription
uristringYesURI of the file to open.
typestringYesType of the file to open.
callbackAsyncCallback<void>YesCallback used to return the result. An error code is returned.

Example

let type: string = "";
let uri: string = "";
document.show(uri, type, (err: TypeError) => {
  //do something
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Core File Kit

harmony 鸿蒙Environment

harmony 鸿蒙FileIO

harmony 鸿蒙FileShare_PolicyErrorResult

harmony 鸿蒙FileShare_PolicyInfo

harmony 鸿蒙error_code.h

harmony 鸿蒙File Management Error Codes

harmony 鸿蒙FileShare

harmony 鸿蒙FileUri

harmony 鸿蒙@ohos.application.BackupExtensionAbility (Backup and Restore Extension Capability) (System API)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/Kyoebq