中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
读取rawfile下的文件如何读取所有的内容?
微信扫码分享
import { common } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; import util from '@ohos.util'; function certVerification(context: common.UIAbilityContext){ try { context.resourceManager.getRawFileContent("test.txt", (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let rawFile = value; const result=util.TextDecoder.create().decodeWithStream(value) console.info('result:'+result) } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`); } } @Entry @Component struct test7 { private context=getContext(this) as common.UIAbilityContext; build() { Button('测试rawfile') .onClick(()=>{ certVerification(this.context) }) } }