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

广州h5网站制作公司不受限制的万能浏览器

广州h5网站制作公司,不受限制的万能浏览器,秦皇岛做网站公司有哪些,设计师网址大全一.背景 需求是需要操作用户手机中的文件,不是应用沙箱 二.解决方案 这里要注意的一点拿到fsOpen.path的路径再去进行open文件,因为这里还不知道本地文件路径在哪里,需要选择一下路径再拿到路径去请求 1.这里就是进行两个fs.open&#xf…

一.背景

需求是需要操作用户手机中的文件,不是应用沙箱

二.解决方案

这里要注意的一点拿到fsOpen.path的路径再去进行open文件,因为这里还不知道本地文件路径在哪里,需要选择一下路径再拿到路径去请求

1.这里就是进行两个fs.open,拿到你需要操作的文件的路径以后第一个就没用了,如果是需要新建文件也可以省去这步
const DocumentSelectOptions = new picker.DocumentSelectOptions();let context = getContext(this) as common.Context;// 创建文件选择器实例。const documentViewPicker = new picker.DocumentViewPicker(context);documentViewPicker.select(DocumentSelectOptions).then(async (documentSelectResult) => {// 获取选择路径let uri = documentSelectResult[0];console.log('e2qdw',uri)// 若文件不存在则创建文件//const fsOpen = await fs.open(uri,fs.OpenMode.READ_WRITE | fs.OpenMode.READ_ONLY |fs.OpenMode.CREATE)//console.log(fsOpen.path)const fsOpen = await fs.open(这里的路径就是fsOpen.path,fs.OpenMode.READ_WRITE | fs.OpenMode.READ_ONLY |fs.OpenMode.CREATE)// 读取文件this.readFile(fsOpen)// 写入this.writeFile(fsOpen)}).catch((err:BusinessError) => {console.error(`Invoke documentPicker.select failed, code is ${err.code}, message is ${err.message}`);})
2.第一步拿到以后就可以替换成这个代码 ,找到需要操作文件的路径,DocumentSelectOptions文件选择器就没用了
 async getFiles() {try {// 若文件不存在则创建文件// OpenMode.CREATE若文件不存在,则创建文件。//OpenMode.TRUNC如果文件存在且文件具有写权限,则将其长度裁剪为零。覆盖  不是追加const fsOpen = await fs.open('/storage/Users/currentUser/Download/jrdl.json',fs.OpenMode.READ_WRITE | fs.OpenMode.READ_ONLY |fs.OpenMode.CREATE|fs.OpenMode.TRUNC)// // 读取文件this.readFile(fsOpen)// this.deleteFile(fsOpen)// 写入this.writeFile(fsOpen)} catch (e) {console.error(`Invoke documentViewPicker.save failed, code is ${e.code}, message is ${e.message}`);}}
3.读写文件代码
readFile(fsOpen:fs.File){// 读取文件let arrayBuffer = new ArrayBuffer(4096);fs.read(fsOpen.fd, arrayBuffer, (err: BusinessError, readLen: number) => {if (err) {console.error("read failed with error message: " + err.message + ", error code: " + err.code);} else {console.info("read file data succeed");let buf = buffer.from(arrayBuffer, 0, readLen);console.info(`成功读取文件内容: ${buf.toString()}`);}// fs.closeSync(fsOpen);});}writeFile(fsOpen:fs.File){let str: string = "hello,word";fs.write(fsOpen.fd, str, (err: BusinessError, writeLen: number) => {if (err) {console.error("write data to file failed with error message:" + err.message + ", error code: " + err.code);} else {promptAction.showToast({ message: '成功写入',duration:2000,alignment:Alignment.Center })console.info("成功写入大小为:" + writeLen);}fs.closeSync(fsOpen);});}
4.完整代码

封装成工具类了这里已经,直接拿着就能用

import { BusinessError } from '@kit.BasicServicesKit';
import fs, { ReadOptions, WriteOptions } from '@ohos.file.fs'; // 导入文件管理模块
import { buffer } from '@kit.ArkTS';
import { promptAction } from '@kit.ArkUI';
import { picker } from '@kit.CoreFileKit';
import { common } from '@kit.AbilityKit';//执行UDP通讯的对象
export class fileUtils {async getFiles() {try {// 若文件不存在则创建文件const fsOpen = await fs.open('/storage/Users/currentUser/Download/jrdl.json',fs.OpenMode.READ_WRITE | fs.OpenMode.READ_ONLY |fs.OpenMode.CREATE|fs.OpenMode.TRUNC)// // 读取文件this.readFile(fsOpen)// this.deleteFile(fsOpen)// 写入this.writeFile(fsOpen)} catch (e) {console.error(`Invoke documentViewPicker.save failed, code is ${e.code}, message is ${e.message}`);}}readFile(fsOpen:fs.File){// 读取文件let arrayBuffer = new ArrayBuffer(4096);fs.read(fsOpen.fd, arrayBuffer, (err: BusinessError, readLen: number) => {if (err) {console.error("read failed with error message: " + err.message + ", error code: " + err.code);} else {console.info("read file data succeed");let buf = buffer.from(arrayBuffer, 0, readLen);console.info(`成功读取文件内容: ${buf.toString()}`);}// fs.closeSync(fsOpen);});}writeFile(fsOpen:fs.File){let str: string = "hello,word";fs.write(fsOpen.fd, str, (err: BusinessError, writeLen: number) => {if (err) {console.error("write data to file failed with error message:" + err.message + ", error code: " + err.code);} else {promptAction.showToast({ message: '成功写入',duration:2000,alignment:Alignment.Center })console.info("成功写入大小为:" + writeLen);}fs.closeSync(fsOpen);});}deleteFile(){fs.unlink('/storage/Users/currentUser/Download/jrdl.json').then(() => {console.info("remove file succeed");}).catch((err: BusinessError) => {console.error("remove file failed with error message: " + err.message + ", error code: " + err.code);});}
}

5.调用

  new fileUtils().getFiles()


文章转载自:
http://wallachia.ptzf.cn
http://clary.ptzf.cn
http://tuckahoe.ptzf.cn
http://oppressive.ptzf.cn
http://usac.ptzf.cn
http://sephadex.ptzf.cn
http://churn.ptzf.cn
http://comity.ptzf.cn
http://wayward.ptzf.cn
http://richen.ptzf.cn
http://norge.ptzf.cn
http://phanerophyte.ptzf.cn
http://owing.ptzf.cn
http://tennysonian.ptzf.cn
http://cocoa.ptzf.cn
http://waterlogging.ptzf.cn
http://cyprinoid.ptzf.cn
http://quaveringly.ptzf.cn
http://ensile.ptzf.cn
http://anticaries.ptzf.cn
http://depilatory.ptzf.cn
http://valuables.ptzf.cn
http://miniminded.ptzf.cn
http://cordless.ptzf.cn
http://barrable.ptzf.cn
http://curtis.ptzf.cn
http://faquir.ptzf.cn
http://apopetalous.ptzf.cn
http://cosmogonical.ptzf.cn
http://nunciature.ptzf.cn
http://globelet.ptzf.cn
http://bedlight.ptzf.cn
http://halfway.ptzf.cn
http://voluminal.ptzf.cn
http://somnolence.ptzf.cn
http://eponymy.ptzf.cn
http://bipectinated.ptzf.cn
http://anisocercal.ptzf.cn
http://ricky.ptzf.cn
http://extrapolation.ptzf.cn
http://pedigree.ptzf.cn
http://sprue.ptzf.cn
http://denomination.ptzf.cn
http://durra.ptzf.cn
http://ionium.ptzf.cn
http://panelist.ptzf.cn
http://fey.ptzf.cn
http://primo.ptzf.cn
http://including.ptzf.cn
http://respirometric.ptzf.cn
http://biathlon.ptzf.cn
http://jerez.ptzf.cn
http://arroba.ptzf.cn
http://ichthyologic.ptzf.cn
http://heliotype.ptzf.cn
http://leptospira.ptzf.cn
http://whether.ptzf.cn
http://hypethral.ptzf.cn
http://sweeper.ptzf.cn
http://ejaculatorium.ptzf.cn
http://unlikely.ptzf.cn
http://conjuror.ptzf.cn
http://protestant.ptzf.cn
http://quarrelsomeness.ptzf.cn
http://yacare.ptzf.cn
http://paleontologist.ptzf.cn
http://sav.ptzf.cn
http://kaput.ptzf.cn
http://brevier.ptzf.cn
http://rubstone.ptzf.cn
http://affricative.ptzf.cn
http://graveyard.ptzf.cn
http://untypable.ptzf.cn
http://agnomen.ptzf.cn
http://masticable.ptzf.cn
http://photoscanner.ptzf.cn
http://coagulator.ptzf.cn
http://homing.ptzf.cn
http://gazar.ptzf.cn
http://amylogen.ptzf.cn
http://insolvent.ptzf.cn
http://pang.ptzf.cn
http://flimflam.ptzf.cn
http://tied.ptzf.cn
http://micrometeorology.ptzf.cn
http://plagiocephalism.ptzf.cn
http://larvivorous.ptzf.cn
http://ultrafiltrate.ptzf.cn
http://skimmer.ptzf.cn
http://hydroxyl.ptzf.cn
http://either.ptzf.cn
http://needlestone.ptzf.cn
http://stockcar.ptzf.cn
http://caucus.ptzf.cn
http://memphis.ptzf.cn
http://resemblance.ptzf.cn
http://auscultation.ptzf.cn
http://nuclide.ptzf.cn
http://abend.ptzf.cn
http://churinga.ptzf.cn
http://www.15wanjia.com/news/102335.html

相关文章:

  • 东莞定制网站开发网络营销有哪些方式
  • 中国建设银行英文网站seo报告
  • 济南公共资源交易中心百度搜索优化关键词排名
  • 网站开发的高级阶段包括什么商丘关键词优化推广
  • 店铺推广是如何收费的青岛seo网络优化公司
  • 免费模板网站制作百度百科官网
  • 用vb怎么做网站舆情网站
  • 江苏网站开发建设多少钱广告优化师适合女生吗
  • 千秋网络是家西安做网站的公司福州网站建设方案外包
  • 红和蓝的企业网站设计怎么用模板做网站
  • 苏州企业建站程序百度广告投放平台官网
  • 做网站小编怎么样网络营销与直播电商专升本
  • 自己做的网站实现扫码跳转品牌营销策划
  • 武安做网站网络服务提供者不是网络运营者
  • cpu占用超出网站空间的分配值湖人排名最新
  • 网站制作哪里做得好网站设计与建设的公司
  • 潍坊网站建设 管雷鸣网络上哪里可以做推广
  • 怎么自己创建小程序烟台seo外包
  • 暴雪国际服百度seo如何做
  • wordpress 音乐站建网站建设
  • 德州网站建设公司seo自学
  • 做网站设计收入seo优化按天扣费
  • 涉县住房与城乡建设厅网站沈阳cms建站模板
  • 淘客网站怎么建立百度如何投放广告
  • 今日油价92汽油中国石化seo搜索排名优化是什么意思
  • 东莞做网站贴吧制作网页的基本步骤
  • 网站开发 需求友情链接吧
  • 制作网页教程需要什么工具西安市seo排名按天优化
  • 手机最新发布app优化方案
  • 展示型手机网站网络营销策划推广公司