C# 调用streamwriter时是否更改路径?

C# 调用streamwriter时是否更改路径?,c#,string,path,directory,streamwriter,C#,String,Path,Directory,Streamwriter,我有以下三行c代码: 当我运行它时,我首先收到以下打印消息,表示名为pageAnnotationTextFilePath的字符串的值: file://C:/Users/USER/Desktop/Accessible/Assets/IO/Books/A community of learners/king/pages/page1.txt 这是正确的,也是应该的。但是,程序的下一行给出了下面的错误。似乎正在发生的事情是StreamWriter初始化类正在更改我的路径——导致项目的位置被追加到我提供

我有以下三行c代码:

当我运行它时,我首先收到以下打印消息,表示名为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)
DirectoryNotFoundException:找不到路径“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路径、FileMode模式、FileAccess访问、FileShare共享、Int32 bufferSize、布尔匿名、FileOptions)
System.IO.FileStream..ctor(System.String路径、FileMode模式、FileAccess访问、FileShare共享)
(带检查的包装器远程处理调用)System.IO.FileStream:.ctor(字符串、System.IO.FileMode、System.IO.FileAccess、System.IO.FileShare)
System.IO.StreamWriter..ctor(System.String路径、布尔追加、System.Text.Encoding编码、Int32 bufferSize)
System.IO.StreamWriter..ctor(System.String路径,布尔追加)
(带检查的包装器远程处理调用)System.IO.StreamWriter:.ctor(字符串,bool)
AnnotationIO+c__迭代器0.MoveNext()(位于Assets/AnnotationIO.cs:27)
UnityEngine.MonoBehavior:启动例程(IEnumerator)
c__迭代器6:MoveNext()(位于Assets/Scripts/GUI/WizardAnnotationGUI.cs:81)
UnityEngine.MonoBehavior:启动例程(IEnumerator)
c__迭代器5:MoveNext()(位于Assets/Scripts/GUI/WizardAnnotationGUI.cs:71)
谢谢你的专业知识

这是一个提示

'找不到路径“C:\Users\USER\Desktop\Accessible\file:\C:\Users\USER\Desktop\Accessible\Assets\IO\Books\a community of learners\king\pages\page1.txt”的一部分'

请注意,您的打印输出是

'file://C:/Users/USER/Desktop/Accessible/Assets/IO/Books/A community of learners/king/pages/page1.txt'

因此,您正在将此字符串馈送给StreamWriter。StreamWriter正在使用此字符串并将其用作相对路径。您的工作目录必须是:

'C:\Users\USER\Desktop\Accessible'

这两个人正在相互依附。长话短说,您必须去掉“file://”

这是一个提示

'找不到路径“C:\Users\USER\Desktop\Accessible\file:\C:\Users\USER\Desktop\Accessible\Assets\IO\Books\a community of learners\king\pages\page1.txt”的一部分'

请注意,您的打印输出是

'file://C:/Users/USER/Desktop/Accessible/Assets/IO/Books/A community of learners/king/pages/page1.txt'

因此,您正在将此字符串馈送给StreamWriter。StreamWriter正在使用此字符串并将其用作相对路径。您的工作目录必须是:

'C:\Users\USER\Desktop\Accessible'


这两个人正在相互依附。长话短说,你必须去掉“file://”

什么是
currentPagePath
value?什么是
currentPagePath
value?啊,这完全有道理。谢谢我想我很好奇为什么它会这样做——但是,唉,比我更伟大的头脑已经预见到这是一条道路。啊,这完全有道理。谢谢我想我很好奇为什么它会这样做——但是,唉,比我更伟大的头脑已经预见到这是一条道路。
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)