C# 判断文件夹 文件是否存在

  public void GetVersion()
    {
        string resFile = Application.streamingAssetsPath + "/version.txt";
        string ResFilePath = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(resFile));
        if (!System.IO.Directory.Exists(ResFilePath))
        {
            System.IO.Directory.CreateDirectory(ResFilePath);
        }
        if (!File.Exists(resFile))//如果不存在就创建file文件夹
        {
            FileStream fs1 = new FileStream(resFile, FileMode.Create, FileAccess.Write);
            StreamWriter sw0 = new StreamWriter(fs1);
            sw0.WriteLine(0.1f);//开始写入值
            sw0.Close(); sw0.Dispose();
            fs1.Close(); fs1.Dispose();
        }
        FileStream fs = new FileStream(resFile, FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);
        version = float.Parse(sr.ReadLine());
        sr.Close(); sr.Dispose();
        fs.Close(); fs.Dispose();
    }

猜你喜欢

转载自blog.csdn.net/qq_36848370/article/details/107931387