[Unity][File][JSON]file.copy的使用方法代码动态创建.json文件

empty.json是在文件夹中新建.txt文件,修改名称以及文件后缀,形成的文件。

public void Test_SaveData()
    {
        if (File.Exists(Application.dataPath + "/Resources/DataSave/Saving001/") == false)
        {
            Directory.CreateDirectory(Application.dataPath + "/Resources/DataSave/Saving001/");
        }

        if (File.Exists(Application.dataPath + "/Resources/empty.json") == true)
        {
            File.Copy(Application.dataPath + "/Resources/empty.json", Application.dataPath + "/Resources/DataSave/Saving001/empty.json");
        }
    }

File.Copy(str_1,str_2);

str_1为要复制的文件名称以及路径。

str_2为要粘贴的文件名称以及路径。可以不为相同的文件名称,但是后缀必须相同。

猜你喜欢

转载自blog.csdn.net/BuladeMian/article/details/81709329