Unity在电脑磁盘创建文件夹

1、我这段代码 可以在Awake 函数中调用,目的是在电脑的D盘创建文件夹名字叫做path,并在创建的path这个文件夹中创建文件名字为Json.txt的文件(这是在D盘中不存在这两个文件的时候才会执行)
2、通过这段代码 可以学会怎么在电脑磁盘上创建文件夹 和文件
3、简单粗暴 上代码

 void FilePathTest()
    {

        // 引入命名空间   using System.IO;
        string path = @"D:/Path";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        else
        {
            print("D盘中已经存在Path文件夹");
        }
        string filepath = path + @"/json.txt";

        if (!File.Exists(filepath))
        {
            File.Create(filepath);

        }
        else
        {
            print("D盘中的path文件夹中已经存在了json.txt文件");
        }
    }

猜你喜欢

转载自blog.csdn.net/weixin_43109909/article/details/84308273