沙箱路径的文件怎么拿取?

更新版本后,不能导出/data/storage/el2/base/haps/entry/files下的文件了,如何导出?

HarmonyOS
2024-05-08 22:18:10
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
南风春和
import buffer from 'hos.buffe'; 
import fs from '@ohos.file.fs'; 
import picker from '@ohos.file.picker'; 
import { BusinessError } from'@ohos.base’; 
 
@Entry 
@Component 
struct Index { 
  @State imageBuffer: ArrayBuffer = new ArrayBuffer(96) 
  @State audioUrl: string = “” 
  @State audioSaveResult: string = “” 
  build() { 
    Row() { 
      Column() { 
Text(“写文件”) 
.onClick(() => { 
// 写入 
}) 
 
    Text("pcmPickerSave") 
      .fontSize(30) 
      .fontWeight(FontWeight.Bold) 
      .onClick(async () => { 
        const audioSaveOptions = new picker.AudioSaveOptions(); // 创建文件管理器选项实例 
        audioSaveOptions.newFileNames = ['AudioViewPicker.pcm']; // 保存文件名(可选) 
        const audioViewPicker = new picker.AudioViewPicker(); 
        audioViewPicker.save(audioSaveOptions).then((audioSelectResult: Array<string>) => { 
          this.audioSaveResult = audioSelectResult[0]; 
          console.info('audioViewPicker.save to file succeed and uri is:' + this.audioSaveResult); 
        }).catch((err: BusinessError) => { 
          console.error(`Invoke audioViewPicker.save failed, code is ${err.code}, message is ${err.message}`); 
        }) 
      }) 
 
    Text("pcmSave") 
      .fontSize(30) 
      .fontWeight(FontWeight.Bold) 
      .onClick(async () => { 
        try { 
          this.imageBuffer = buffer.from("hello word").buffer 
          //使用读取的buffet保存 
          let file2 = fs.openSync(this.audioSaveResult, fs.OpenMode.READ_WRITE); 
          let writeLen = await fs.write(file2.fd, this.imageBuffer); 
          fs.closeSync(file2); 
          console.info("msgXucan [picker] writeOnly writeLen = " + writeLen); 
          AlertDialog.show({ message: '已保存至本地!' }); 
        } catch (error) { 
          let err: BusinessError = error as BusinessError; 
          console.info("[picker] writeOnly error: " + JSON.stringify(err)); 
        } 
      }) 
  }.width('100%') 
      .height('100%') 
    } 
    .height(‘100%’) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.

通过filePick的方式写入到公共文件目录,然后通过hdc命令或者ide取出到电脑

分享
微博
QQ
微信
回复
2024-05-09 11:52:38
相关问题
HarmonyOS 预览沙箱路径文件失败
679浏览 • 1回复 待解决
修改沙箱路径下json文件指定内容
3003浏览 • 1回复 待解决
ETs,对沙箱路径json文件内容遍历
3872浏览 • 1回复 待解决
如何使用Image加载沙箱路径图片资源
2570浏览 • 2回复 待解决
HarmonyOS 沙箱文件拷贝
1310浏览 • 1回复 待解决