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

上海新闻综合频道在线直播seo优化排名营销

上海新闻综合频道在线直播,seo优化排名营销,网站建设业务怎么做,小程序模板源代码参考 参考:老孟 文件存储和网络请求 数据存储 Dart的 IO 库包含了文件读写的相关类,它属于 Dart 语法标准的一部分,所以通过 Dart IO 库,无论是 Dart VM 下的脚本还是 Flutter,都是通过 Dart IO 库来操作文件的。但…

参考

参考:老孟 文件存储和网络请求

数据存储

Dart的 IO 库包含了文件读写的相关类,它属于 Dart 语法标准的一部分,所以通过 Dart IO 库,无论是 Dart VM 下的脚本还是 Flutter,都是通过 Dart IO 库来操作文件的。但是不同的平台对应的文件系统是不同的,比如文件路径,因此通常使用Google 官方维护的插件 path_provider。

安装

在项目的 pubspec.yaml 文件中添加依赖

dependencies:path_provider: ^2.0.11

安装

flutter pub get

常用方法

getTemporaryDirectory
临时目录,适用于下载的缓存文件,此目录随时可以清除,此目录为应用程序私有目录,其他应用程序无法访问此目录。

getApplicationSupportDirectory
获取应用程序的支持目录。这个函数返回一个Future<Directory>对象,表示应用程序的支持目录。

getLibraryDirectory
返回应用程序的库目录。这个目录通常用于存储应用程序的共享库或插件。

getApplicationDocumentsDirectory
应用程序的文档目录。文档目录是应用程序可以使用的持久性存储空间,通常用于存储用户生成的文件或其他数据。

getExternalStorageDirectory
应用程序可以访问顶级存储的目录的路径。由于此功能仅在Android上可用,因此应在发出此函数调用之前确定当前操作系统。

getExternalCacheDirectories
存储特定于应用程序的外部缓存数据的目录的路径。

getDownloadsDirectory
存储下载文件的目录的路径,这通常仅与台式机操作系统有关。 在Android和iOS上,此函数将引发[UnsupportedError]异常。

方法使用场景

下面从 Android 和 iOS 平台的角度介绍其文件路径,最后给出路径使用的建议以及使用过程中需要注意的事项。

安卓文件存储

Android 文件存储分为内部存储和外部存储。

内部存储:

  • 其他应用无法访问这些数据
  • 当应用卸载的时候,这些数据也会被删除,避免垃圾文件
  • 不需要申请额外权限
  • 存储的空间有限,此目录数据随时可能被系统清除,也可以通过 设置 中的 清除数据 可以清除此目录数据。

内部存储目录结构:

  • cache 目录:对应 getTemporaryDirectory 方法,用于缓存文件,此目录随时可能被系统清除。
  • files 目录:对应 getApplicationSupportDirectory 方法。
  • code_cache:此目录存储 Flutter 相关代码和资源
  • shared_prefs:SharePreferences(轻量级的本地存储) 的默认路径
  • app_flutter:对应 getApplicationDocumentsDirectory方法。
  • app_flutter/dbName:使用 sqlite(轻量级的关系型数据库,用于本地存储和管理应用程序的数据) 的默认路径,sqlite 也可以指定位置。

外部存储

  • 当应用卸载的时候,这些数据也会被删除,避免垃圾文件
  • 不需要申请额外权限
  • 空间大且不会被系统清除,通过 设置 中的 清除数据 可以清除此目录数据。
  • 用户可以直接对文件进行删除、导入操作。

外部存储目录结构

  • cache:缓存目录,对应 getExternalCacheDirectories 方法。
  • files:对应 getExternalStorageDirectories 方法。

苹果文件存储

iOS 文件存储相比 Android 要简单的多,因为 iOS 对用户隐私保护非常严格,每个 iOS 应用程序都有一个单独的文件系统,而且只能在对应的文件系统中进行操作,此区域被称为沙盒。

每个应用沙盒含有3个文件夹:Documents, Library 和 tmp:

  • Documents:应用程序数据文件写入到这个目录下。这个目录用于存储用户数据。保存应用程序的重要数据文件和用户数据文件等。对应 getApplicationDocumentsDirectory 方法。
  • Library:对应 getLibraryDirectory 方法
  • tmp:存放临时文件,不会被备份,而且这个文件下的数据有可能随时被清除的可能,按照官方说法每三天清理一次缓存数据。

总结

  • SharePreferences 和 sqlite 数据建议存放在内部存储,插件已经帮我们完成了,无需手动处理。
  • 严格保密的数据,比如用户数据,建议存放在内部存储,对应 getApplicationSupportDirectory 方法。
  • 其余所有的数据建议存放 Android/data/包名/ ,对应 getExternalCacheDirectories 和 getExternalStorageDirectories 方法。

基本使用

flutter官方示例

文件读写

文件夹

创建文件夹

ElevatedButton(onPressed: () async{// 获取应用程序目录Directory appDocumentDriectory = await getApplicationDocumentsDirectory();// 路径,Platform.pathSeparator 平台下的路径分隔符String path = '${appDocumentDriectory.path}${Platform.pathSeparator}myAppName';// 读取对应路径下的文件夹var dir = Directory(path);if(dir.existsSync()){print("当前文件夹已存在");}else{// 创建文件,可选参数recursive:true表示可以创建嵌套文件夹,false表示只能创建最后一级文件夹(上一级文件不存在会报错),默认falsevar result = await dir.create(recursive: true);print("文件创建成功:${result}");}}, child: const Text("创建文件夹"));

在这里插入图片描述

遍历文件夹

ElevatedButton(onPressed: () async{// 获取应用程序目录Directory appDocumentDirectory = await getApplicationDocumentsDirectory();String path = '${appDocumentDirectory.path}${Platform.pathSeparator}';// 文件列表,可选参数recursive,默认值为false,只遍历当前目录;设置为true时会遍历当前目录及子目录Stream<FileSystemEntity> fileList = Directory(path).list();await for(FileSystemEntity fileSystemEntity in fileList){print(fileSystemEntity);}
}, child: const Text("遍历文件"))

在这里插入图片描述
判断文件的类型

await for(FileSystemEntity fileSystemEntity in fileList){print('$fileSystemEntity');FileSystemEntityType type = FileSystemEntity.typeSync(fileSystemEntity.path);
}

文件的类型:

  • file:文件
  • directory:文件夹
  • link:链接文件,比如:HTML文件、PDF文件、图片文件、音频文件、文本文件、JSON文件
  • notFound:未知

文件夹重命名

_dirRename() async{Directory documentsDirectory = await getApplicationDocumentsDirectory();String path = '${documentsDirectory.path}${Platform.pathSeparator}dirName';var dir = Directory(path);var newName= await dir.rename('${dir.parent.absolute.path}${Platform.pathSeparator}newName');
}

删除文件夹

ElevatedButton(onPressed: () async{// 获取应用程序文件目录Directory appDocumentDirectory = await getApplicationDocumentsDirectory();String path ='${appDocumentDirectory.path}${Platform.pathSeparator}myAppName';try{// 可选参数recursive,默认false,只删除文件夹,如果文件夹下有内容则无法删除并抛出异常;true删除文件夹及文件夹下所有内容var dir = await Directory(path).delete();print('文件夹$path删除成功');}catch(err){print('文件夹$path删除失败:$err');}}, child: const Text("删除文件夹"))

在这里插入图片描述

文件

创建文件

ElevatedButton(onPressed: () async{// 获取应用程序目录Directory appDocumentDirectory = await getApplicationDocumentsDirectory();// 路径String path = '${appDocumentDirectory.path}${Platform.pathSeparator}myAppName${Platform.pathSeparator}test.txt';File file = File(path);if(file.existsSync()){print("文件已存在");}else{// 文件创建也存在recursive属性var file = await File(path).create();print("文件创建成功:$file");}}, child: const Text("创建文件"))

在这里插入图片描述
写入数据

写入字符串,覆盖写入

ElevatedButton(onPressed: () async{// 获取应用程序目录Directory appDocumentDirectory = await getApplicationDocumentsDirectory();// 路径String path = '${appDocumentDirectory.path}${Platform.pathSeparator}myAppName${Platform.pathSeparator}test.txt';File file = File(path);if(file.existsSync()){var res = await file.writeAsString("写入数据");print("写入成功:$res");}else{print("文件不存在");}
}, child: const Text("写入数据")),

在这里插入图片描述
写入bytes 数据,覆盖写入

file.writeAsBytes(Utf8Encoder().convert("bytes 格式"));

追加写入

file.openWrite(mode: FileMode.append).write('追加写入');

读取数据
读取字符串

ElevatedButton(onPressed: () async {//  应用程序目录Directory appDocumentDirectory =await getApplicationDocumentsDirectory();// 路径String path ='${appDocumentDirectory.path}${Platform.pathSeparator}myAppName${Platform.pathSeparator}test.txt';File file = File(path);if (file.existsSync()) {var res = await file.readAsString(encoding: utf8);print("文件读取成功,内容是:$res");} else {print("文件不存在");}},child: const Text("文件读取"))

在这里插入图片描述
按行读取数据

List<String> lines = await file.readAsLines();
lines.forEach((element) {print('$element');
});

读取 bytes 并转换为String

Utf8Decoder().convert(await file.readAsBytes());

删除

file.delete();

读取 assets 文件

读取项目中文件,项目中使用的文件一般都放在lib/assets
在这里插入图片描述
如果需要访问,需要在pubspec.yaml 文件中添加配置,例如:

assets:- assets/json/

读取

_loadAsset(BuildContext context) async{var jsonStr = await DefaultAssetBundle.of(context).loadString('assets/json/data.json');var list = json.decode(jsonStr);list.forEach((element) {print('$element');});
}

文章转载自:
http://standaway.c7493.cn
http://eponym.c7493.cn
http://repressed.c7493.cn
http://isopentyl.c7493.cn
http://copyist.c7493.cn
http://photocoagulating.c7493.cn
http://sublimer.c7493.cn
http://disoblige.c7493.cn
http://mammie.c7493.cn
http://antrim.c7493.cn
http://quoter.c7493.cn
http://ensue.c7493.cn
http://catabasis.c7493.cn
http://thallophyte.c7493.cn
http://kluck.c7493.cn
http://windsail.c7493.cn
http://meritocracy.c7493.cn
http://alchemical.c7493.cn
http://polynosic.c7493.cn
http://lincolniana.c7493.cn
http://netting.c7493.cn
http://verminate.c7493.cn
http://maderization.c7493.cn
http://maas.c7493.cn
http://barrelful.c7493.cn
http://eleventh.c7493.cn
http://gum.c7493.cn
http://band.c7493.cn
http://ambeer.c7493.cn
http://noogenesis.c7493.cn
http://eez.c7493.cn
http://sculk.c7493.cn
http://mealie.c7493.cn
http://vile.c7493.cn
http://preshrunk.c7493.cn
http://panplegia.c7493.cn
http://demirelievo.c7493.cn
http://saltation.c7493.cn
http://hypermetropia.c7493.cn
http://jointed.c7493.cn
http://decimetre.c7493.cn
http://ileal.c7493.cn
http://crater.c7493.cn
http://salicyl.c7493.cn
http://seignior.c7493.cn
http://morgen.c7493.cn
http://kansas.c7493.cn
http://altaic.c7493.cn
http://bin.c7493.cn
http://redemptorist.c7493.cn
http://syphon.c7493.cn
http://decantation.c7493.cn
http://deschooler.c7493.cn
http://blackfoot.c7493.cn
http://slipper.c7493.cn
http://amenorrhoea.c7493.cn
http://sled.c7493.cn
http://sahiwal.c7493.cn
http://lovelace.c7493.cn
http://lequear.c7493.cn
http://reinflame.c7493.cn
http://coumaphos.c7493.cn
http://banausic.c7493.cn
http://wahabee.c7493.cn
http://pyrotoxin.c7493.cn
http://rescuee.c7493.cn
http://electrommunication.c7493.cn
http://impartially.c7493.cn
http://resupinate.c7493.cn
http://grizzle.c7493.cn
http://micrometeorite.c7493.cn
http://ceviche.c7493.cn
http://maracaibo.c7493.cn
http://muf.c7493.cn
http://revivable.c7493.cn
http://brooklime.c7493.cn
http://remorsefully.c7493.cn
http://emblem.c7493.cn
http://fourthly.c7493.cn
http://gait.c7493.cn
http://superbly.c7493.cn
http://unauthoritative.c7493.cn
http://kum.c7493.cn
http://reinterrogate.c7493.cn
http://suprarenal.c7493.cn
http://milage.c7493.cn
http://semantic.c7493.cn
http://flickertail.c7493.cn
http://succursal.c7493.cn
http://nematology.c7493.cn
http://pimpmobile.c7493.cn
http://veni.c7493.cn
http://agio.c7493.cn
http://immunocompetence.c7493.cn
http://collaborationism.c7493.cn
http://fogbow.c7493.cn
http://peckerhead.c7493.cn
http://lincoln.c7493.cn
http://creepered.c7493.cn
http://associator.c7493.cn
http://www.zhongyajixie.com/news/72728.html

相关文章:

  • 免费电子商务网站建设google学术搜索
  • 长春火车站属于哪个区seo文章生成器
  • 龙岩做网站新闻发布
  • 南通企业网站建设公司网络渠道有哪些
  • 关于做教育新闻的网站百度客户服务电话
  • 录音转文字网站开发长尾关键词举例
  • 做手机网站在线培训
  • 福州 网站制作 外贸网络广告推广服务
  • 做社交网站开发seo排名优化收费
  • 小型购物网站建设软件开发工程师
  • 网站开发前调查企业网络营销推广平台
  • vps网站设置网站统计器
  • 帝国网站系统做专题搜索网站排名优化
  • 网站建设公司专业网站制作开发痘痘怎么去除效果好
  • 企业免费网站制作比较好的新闻最新头条10条
  • 二次开发手册安卓优化
  • 邯郸网站建设小红书关键词排名优化
  • 做旅行网站好怎么推广一个app
  • 兼职做网站的费用百度联盟怎么加入赚钱
  • 动态网站开发全流程图网站优化的关键词
  • 被黑网站新闻头条最新
  • wordpress获取页面tag关键词seo如何优化
  • 域名申请证书seo关键字怎么优化
  • 集团定制网站建设公司网站搭建模板
  • 网站怎么架设旅行网站排名前十名
  • 网站小程序定制公司sem投放是什么意思
  • 招远网站建设近三天时政热点
  • 360推广 网站建设搜索引擎营销的四种方式
  • 如何做点对点视频网站免费人脉推广软件
  • 个人网站做百度云电影链接犯法吗做网站设计哪里有