C# Unity file.exists不会为现有文件返回true

C# Unity file.exists不会为现有文件返回true,c#,unity3d,C#,Unity3d,在Unity c#中,file.exists始终返回false public class StartMenu : MonoBehaviour { public GameObject playButton; public GameObject loadButton; // Use this for initialization void Start() { // generate correct pathname format for device string path = P

在Unity c#中,file.exists始终返回false

public class StartMenu : MonoBehaviour
{
public GameObject playButton;
public GameObject loadButton;

// Use this for initialization
void Start()
{
    // generate correct pathname format for device
    string path = Path.Combine(Application.persistentDataPath, "Data");
    path = Path.Combine(path, "Aralimar.data");

    Debug.Log(path);
    Debug.Log(System.IO.File.Exists("path"));

    if (System.IO.File.Exists("path"))
    {
        Debug.Log("Save game exists");
        playButton.SetActive(true);
        loadButton.SetActive(true);
    }
}
该文件存在,如果我将调试日志中的路径粘贴到Windows资源管理器中,它将毫无问题地打开。一个相关的函数LoadGameData直接从startmenu调用,它使用完全相同的路径结构,因此Unity可以找到并打开该文件

 public void LoadGameData()
{
    // generate correct pathname format for device
    string path = Path.Combine(Application.persistentDataPath, "Data");
    path = Path.Combine(path, "Aralimar.data");

    Debug.Log("Loading data from " + path);

    // load xml file into GameData
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(GameData));
    FileStream fileStream = new FileStream(path, FileMode.Open);
    gameData = xmlSerializer.Deserialize(fileStream) as GameData;
    fileStream.Close();
}
调试语句:

C:/Users/*myname*/AppData/LocalLow/Wyeknott/Aralimar\Data\Aralimar.data

False

Loading data from C:/Users/*myname*/AppData/LocalLow/Wyeknott/Aralimar\Data\Aralimar.data
系统详细信息:Windows 10,unity 2017.3.0f3


谢谢

System.IO.File.Exists(“路径”)
更改为
System.IO.File.Exists(路径)

“path”
是普通字符串,不带引号的
path
是对变量的引用


这是尽可能简单的。不知道你是从哪里来的C#但我建议你读一些关于它的书或教程

它应该是
System.IO.File.Exists(path))
?请注意,我删除了路径周围的双引号。谢谢。我都快瞎了,真不错。如果你的问题得到了回答,请接受答案