如何将文件转换成字符串

如何将文件转换成字符串

HarmonyOS
2024-07-23 11:26:20
1153浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
人提唱盘

将rawfile下的文件转换为字符串或者Base64格式数据进行传输。

getContext().resourceManager.getRawFileContent('MyStr.txt').then((value: Uint8Array) => { 
  let textDecoder: util.TextDecoder = util.TextDecoder.create(); // 调用util模块的TextDecoder类 
  let retStr: string = textDecoder.decodeWithStream(value); // 对Uint8Array解码 
  let strBase64 = new util.Base64Helper().encodeToStringSync(value); 
  console.info(retStr); 
  console.info(strBase64); 
}).catch((error: BusinessError) => { 
  console.info('getRawFileContent promise error is ' + error); 
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
分享
微博
QQ
微信
回复
2024-07-23 18:42:43


相关问题
HarmonyOS将对象转换成字符串的方法
1659浏览 • 1回复 待解决
请问如何将openblock文件转换成exe文件
3159浏览 • 0回复 待解决
HarmonyOS 如何将汉字转换成拼音
1013浏览 • 1回复 待解决
如何将字符串转换为浮点数。
1452浏览 • 1回复 待解决
PixelMap类型怎么转换成Base64字符串
1616浏览 • 1回复 待解决
如何将Android的APP转换成鸿蒙的?
386浏览 • 1回复 已解决
如何将某个时间转换成距现在的时间
1261浏览 • 1回复 待解决
如何将JSON字符串转为Map
1033浏览 • 1回复 待解决
如何将JSON字符串转Class对象
1169浏览 • 1回复 待解决
如何将字符串转为Uint8Array?
1891浏览 • 1回复 待解决
如何将Uint8Array转字符串
1471浏览 • 1回复 待解决
如何将JSON字符串转Class对象数组?
1279浏览 • 1回复 待解决
HarmonyOS 如何将md5变成字符串
1024浏览 • 1回复 待解决