当前位置: 首页 > news >正文

鸿蒙:将项目的rawfile目录下全部文件拷贝到app沙箱目录(第二种方案)

1. 前言

上篇博客跟大家分享了一种压缩后拷贝的方法,这种的相对比较麻烦,本篇博客分享一个更为简单的方法。

2. 参考文档

https://developer.huawei.com/consumer/cn/doc/architecture-guides/common-v1_26-ts_93-0000002306064776https://developer.huawei.com/consumer/cn/doc/architecture-guides/common-v1_26-ts_93-0000002306064776

3. 核心思路

rawfile目录下的文件夹直接复制到resfile目录下,然后再复制到沙箱。

4. 核心代码

async copyResfileDir() {await fs.copyDir(this.resfileDir, this.filesDir)this.showAlertDialog("拷贝成功")
}

5. 运行效果

6. 完整代码

import { fileIo as fs } from '@kit.CoreFileKit'@Entry
@ComponentV2
struct Index {context = this.getUIContext().getHostContext()!@Local resfileDir: string = ""@Local filesDir: string = ""showAlertDialog(mes: string) {this.getUIContext().showAlertDialog({ message: mes })}getResfileDir() {this.resfileDir = this.context.resourceDirthis.showAlertDialog("resfileDir路径" + this.resfileDir)}getFilesDir() {this.filesDir = this.context.filesDirthis.showAlertDialog("filesDir路径" + this.filesDir)}async copyResfileDir() {await fs.copyDir(this.resfileDir, this.filesDir)this.showAlertDialog("拷贝成功")}async printFilesDir() {const list = await fs.listFile(this.filesDir)this.showAlertDialog(list.join("\n"))}async showRawfiles() {const list = await fs.listFile(this.filesDir + "/resfile")this.showAlertDialog(list.join("\n"))}build() {Column({ space: 100 }) {Text("依次点击下方按钮").fontSize(30).fontWeight(FontWeight.Bold)Column({ space: 20 }) {Text("resfileDir路径" + this.resfileDir)Button("获取resfileDir路径").onClick(() => {this.getResfileDir()})Text("filesDir路径" + this.filesDir)Button("获取filesDir路径").onClick(() => {this.getFilesDir()})Button("将resfileDir下的文件全部拷贝到沙箱目录").onClick(() => {this.copyResfileDir()})Button("获取沙箱目录下的所有文件").onClick(() => {this.printFilesDir()})Button("进入沙箱的resfile文件夹查看").onClick(() => {this.showRawfiles()})}}.width('100%').height("100%").justifyContent(FlexAlign.Center)}
}

觉得有帮助可以点赞或收藏

http://www.dtcms.com/a/478731.html

相关文章:

  • PWM输出频率计
  • RuntimeBroker.exe应用程序错误?3种专业修复方法
  • PHP网站开发有哪些框架互联网推广品牌
  • [Power BI] VALUES函数
  • Idea 启动报 未找到有效的 Maven 安装问题
  • 智慧公厕管理系统全流程智能化
  • Pinia 状态管理:从入门到精通
  • 江苏城乡住房建设厅网站做公众号微网站
  • iBizModel 系统数据同步代理(PSSYSDATASYNCAGENT)与实体数据同步(PSDEDATASYNC)模型详解
  • 深度相机结构光vs.激光雷达
  • 我的全栈学习之旅:Colcon, CMake, Ninja/Make,编译器之间的关系
  • 【数值分析】解线性方程组的迭代法经典算法
  • 东莞网站空间wordpress迁移hexo
  • 小白如何建网站wordpress gstatic
  • 关于JMM
  • 嵌入式学习笔记- 单片机的低功耗以及唤醒
  • Dify从入门到精通 第12天 RAG知识库概念引入:深入理解知识库、分词与向量化
  • C语言项目:文本统计程序
  • 龙游县建设局网站晋州建设规划局网站
  • Java-Spring入门指南(二十四)SSM整合HTML:解决CSS/JS静态资源被过滤问题
  • 安阳做网站多少钱邢台最新通告今天
  • 如何做高并发网站的架构设计地方型旅游网站
  • 网站文章伪原创怎么做网站建设策划基本流程图
  • 条件概率、全概率、贝叶斯
  • 用mvc做网站报告自己的电脑做服务器搭建网站
  • 更换网站模板html所有标签大全
  • 软件模拟存储,SCSI映射StarWind5.4 企业版
  • DFS和BFS算法和回溯算法
  • c++ 标准模板库练习
  • 购物网站建设费用wordpress调用python脚本