unity创建文件夹 读取文件 C# 对文件操作

PC端

路径写法

   string filepath = @"d:/picslt";
 filepath = Application.streamingAssetsPath + @"/StreamingAssets/配置相机.txt";

安卓端  放在Application.persistentDataPath

#if UNITY_ANDROID
        src = new string[1] { "Android" };
        srcs = Application.persistentDataPath.Split(src, System.StringSplitOptions.None);
        filepath = srcs[0] + "pic";
        filepathsst = srcs[0] + "picsltslt";
        imgffpath = srcs[0]  + "imgffpath";
        jsonpath = Application.persistentDataPath + "/newjson.txt";
#endif

判断文件是否存在 没有就创建    File

 if (!File.Exists(imgffpath))
        {
            File.Create(imgffpath);
         }

判断文件夹是否存在 没有就创建   Directory

 if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }

复制文件并且按照序列保存  Fileinfo 

 if (File.Exists(path))
            {
                FileInfo fi = new FileInfo(path);
                fi.CopyTo(imgffpath + "/" + i.ToString("00000") + ".jpg", true);
            }

 

你可能感兴趣的:(unity)