unity 安卓 如何把StreamingAssets目录下的文件 拷贝到安卓持久化目录(persistentDataPath)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wengpanfeng/article/details/79773975

    这里演示如何把数据库文件从StreamingAssets中拷贝到persistentDataPath目录下。

    我的数据库文件名称为:map_data.db,放在Unity3d的StreamingAssets/db/map_data.db中。

    我的数据库文件的路径为:string path =Application.streamingAssetsPath + "/db/map_data.db" ;

    [map_data.db:是数据库的名称]

   StreamingAssets里面的数据库需要www下载.简单的写一下代码

   WWW www =new WWW(path);

    yield return www;

    if(www.idDone){

            //拷贝数据库到指定路径
            string path = Application.persistentDataPath+ "/" + "map_data.db";

            File.WriteAllBytes(path, www.bytes);

    }

这样就完成从streamingassets拷贝到持久化目录当中。

工程打包以后运行在夜神模拟器上,可以查看验证一下,是否拷贝出来。如下图:


成功拷贝!拷贝其它文件也是这样 。

猜你喜欢

转载自blog.csdn.net/wengpanfeng/article/details/79773975
今日推荐