所以,我有以下三行 c# 代码:
string pageAnnotationTextFilePath = currentPagePath.Substring(0, currentPagePath.Length-4) + ".txt";
print (pageAnnotationTextFilePath);
StreamWriter sw = new StreamWriter(pageAnnotationTextFilePath, false);
当我运行它时,我首先收到以下打印消息,表示名为 pageAnnotationTextFilePath 的字符串的值:
file://C:/Users/USER/Desktop/Accessible/Assets/IO/Books/A community of learners/king/pages/page1.txt
这是正确的,也应该如此。但是,程序中的下一行给了我下面的错误。似乎正在发生的事情是我的路径正在被 StreamWriter 初始化类改变——导致项目的位置被附加到我提供的路径的第一部分。为什么要这样做,为什么要这样做?我在堆栈跟踪中提到的路径就在顶部,这里:
DirectoryNotFoundException: Could not find a part of the path "C:\Users\USER\Desktop\Accessible\file:\C:\Users\USER\Desktop\Accessible\Assets\IO\Books\A community of learners\king\pages\page1.txt".
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize)
System.IO.StreamWriter..ctor (System.String path, Boolean append)
(wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string,bool)
AnnotationIO+<SaveAllObjectDataToTextFile>c__Iterator0.MoveNext () (at Assets/AnnotationIO.cs:27)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
<SaveDataToBooksFolder>c__Iterator6:MoveNext() (at Assets/Scripts/GUI/WizardAnnotationGUI.cs:81)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
<AutoSave>c__Iterator5:MoveNext() (at Assets/Scripts/GUI/WizardAnnotationGUI.cs:71)
感谢您的专业知识!