关于Application.persistentDataPath在安卓路径的坑 您所在的位置:网站首页 taptap保存的图片在哪 关于Application.persistentDataPath在安卓路径的坑

关于Application.persistentDataPath在安卓路径的坑

2023-08-27 07:41| 来源: 网络整理| 查看: 265

1.首先Application.persistentDataPath路径在安卓加载的文件是些能被修改的文件才放在这里。 2.Application.persistentDataPath+“/”+“文件名称+后缀“。

加载文件

那我们加载安卓Application.persistentDataPath路径下的文件如何加载呢? 1.一般如果是些数据文件首次加载都是放在Application.streamingAsset路径下的 //加载文件时判断文件是否存在

if (!File.Exists(path)) //判断文件是否存在 { //那就从Application.streamingAsset路径复制到Application.persistentDataPath路径下。 //将文件从Application.streamingAsset路径复制到Application.persistentDataPath的方法如下: CopyFormStreamassetToPersistent(fileName); } //文件存在了就直接读取数据了 string data = File.ReadAllText(path);

//将文件从Application.streamingAsset路径复制到Application.persistentDataPath的方法如下

public void CopyFormStreamassetToPersistent(string fileName) { string formPath; string toPath; formPath = Application.streamingAssetsPath + "/" + fileName; toPath=Application.persistentDataPath + "/" + file_name; W W W w=new WWW(formPath) while(!w.isDone){} if(w.error==null) { File.WriteAllBytes(toPath, w.bytes); } }

2.那么还有些文件是一开始没有的怎么办呢?

//首先需要还是判断文件是否存在的问题, if (File.Exists(path)) //判断文件是否存在 { string data = File.ReadAllText(path); } //创建文件 StreamWriter sw; FileInfo t = new FileInfo(path); sw = t.CreateText(); //把你需要的文件数据写入进去 sw.Write(data.ToString()); sw.Close(); sw.Dispose(); 保存修改文件

1.一般如果是些数据文件首次加载都是放在Application.streamingAsset路径下的

StreamWriter sw; FileInfo t = new FileInfo(path); if (!File.Exists(path)) //判断文件是否存在 { //那就从Application.streamingAsset路径复制到Application.persistentDataPath路径下。 CopyFormStreamassetToPersistent(fileName); }

2.重新创建文件并修改保存文件 【

//如果是一些文件需要直接添加的数据 sw= t.AppendText //如果一些文件需要修改文件的我自己的做法是直接删除 File.Delete(path); sw = t.CreateText();

sw.Write(data.ToString());//这个数据自己添加 sw.Close(); sw.Dispose();


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有