簡體   English   中英

將文件寫入 Hololens 文檔目錄時出現問題。 DirectoryNotFoundExcpetion

[英]Issues writing files to Hololens Documents directory. DirectoryNotFoundExcpetion

使用 HoloLens2 模擬器時,我能夠成功地將 my.csv 文件生成到我的桌面路徑(例如 C:\Users\name\Desktop); 但是,當我使用路徑時出現 DirectoryNotFoundException 錯誤(如 Windows 設備門戶文件資源管理器上所示)U:\Users\name\Documents。

錯誤:

DirectoryNotFoundException:找不到路徑“U:\Users\name\Documents\rWrist.csv”的一部分。 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO. FileOptions 選項)[0x00000] 在 <00000000000000000000000000000000>:0

代碼:

string basePath = @"U:\Users\name\Documents\";

    foreach (var getSave in getDictionary)
    {
        string saveLocation = $"{basePath}{getSave.Key}.csv";
        File.WriteAllText(saveLocation, null);

        using (StreamWriter sw = new StreamWriter(saveLocation))
        {
            sw.WriteLine("{0},{1},{2},{3}", "Time", "xPos", "yPos", "zPos");

            foreach (var kvp in getSave.Value)
            {
                sw.WriteLine("{0},{1},{2},{3}", kvp.Key, kvp.Value.x, kvp.Value.y, kvp.Value.z);
            }
        }
    }

任何幫助將非常感激!

Windows 設備門戶上出現的路徑不能直接訪問。 據我所知,它們是內部的。

您可以改為使用Application.persistentDataPath來存儲數據。
然后它將被保存到“ User Folders\LocalAppData\ProjectName\LocalState\.. ”,如 Windows 設備門戶所示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM