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

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

HarmonyOS
2024-05-08 22:18:10
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
post_cj
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%’) 
  } 
}

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

分享
微博
QQ
微信
回复
2024-05-09 11:52:38
相关问题
ETs,对沙箱路径json文件内容遍历
1525浏览 • 1回复 待解决
修改沙箱路径下json文件指定内容
1027浏览 • 1回复 待解决
怎样查看应用沙箱文件
176浏览 • 1回复 待解决
分享沙箱文件,应用可分享单个文件
159浏览 • 1回复 待解决
如何获取应用自身文件路径
339浏览 • 1回复 待解决
鸿蒙如何获取资源文件路径
13941浏览 • 3回复 待解决
fileio.open文件路径错误怎么回事啊?
1180浏览 • 1回复 待解决
Harmony 如何读取本地视频文件路径
12783浏览 • 2回复 待解决