各平台Path

2018-09-17  本文已影响0人  叫我颜先生

简介

  1. 三个路径:dataPath,persistentDataPath,streamingAssetsPath
  2. 三个平台:pc,android,ios
  3. 两个操作:读写

个人项目,项目名路径略有不同


pc

  1. 路径(Application+filename)

    • dataPath:项目所在Assets

      C:/Users/yan/Documents/My/Assets\an.txt

    • persistentDataPath:用户数据目录

      C:/Users/yan/AppData/LocalLow/DefaultCompany/My\an.txt

    • streamingAssetsPath:项目所在StreamingAssets

      C:/Users/yan/Documents/My/Assets/StreamingAssets\an.txt

  2. 读(Application+filename)

    • file/stream:路径不变
    • www:路径不变
  3. 写(Application+filename)

    • 路径不变

总结:

  1. 关于streamingAssetsPath与dataPath:

    streamingAssetsPath+filename=dataPath+/StreamingAssets+filename


android(datapath没用 省略 被安卓折腾过 写一下实践的心得)

  1. 路径(Application+filename)

  2. 读(Application+filename)

    • file/stream:

      • persistentDataPath:ok

      • streamingAssetsPath:无

    • www:

      • persistentDataPath:ERROR(输出为Accept)

      • streamingAssetsPath:ok

  3. 读(file://+Application+filename)

    • file/stream:

      • persistentDataPath:无

      • streamingAssetsPath:无

    • www:

      • persistentDataPath:ok

      • streamingAssetsPath:无

  4. 写(Application+filename)

    • persistentDataPath:

      /storage/emulated/0/Android/data/com.Test.My/files/an.txt

    • streamingAssetsPath:

      ERROR(移动端此目录只读)

总结:

  1. dataPath:不用

  2. 只读:streamingAssetsPath,必须WWW加载,路径名:Application+filename

    (只读不可删除,放二进制文件,尽量不放ab包,ad包解压后原文件还在)

  3. 读写:persistentDataPath,一种file/stream读写,路径名:Application+filename

    另一种WWW加载,路径名:file://+Application+filename

    (生成文件文件夹可看到,运行时才能写入读取)

  4. 打包WritePermission尽量选择SD卡,沙盒模式需要Root看到目录,而且新型和老式有点区别,要是手机没有SD,会自己装在沙盒

  5. 有文件需要读写,可以将要读写文件放入Resources或者streamingAssetsPath,开始的时候就将文件从Resources或streamingAssetsPath拷贝到persistentDataPath

  6. 关于streamingAssetsPath与dataPath:

    streamingAssetsPath+filename=jar:file://+dataPath+!/assets/+filename


上一篇 下一篇

猜你喜欢

热点阅读