0

したがって、次の3行の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)

あなたの専門知識をありがとう!

4

1 に答える 1

3

これはヒントです

'パスの一部が見つかりませんでした"C:\ Users \ USER \ Desktop \ Accessible \ file:\ C:\ Users \ USER \ Desktop \ Accessible \ Assets \ IO \Books\学習者のコミュニティ\king\ pages \ page1.txt "'

プリントアウトが

'file:// C:/ Users / USER / Desktop / Accessible / Assets / IO /Books/学習者のコミュニティ/king/pages/page1.txt'

したがって、この文字列をStreamWriterにフィードしています。StreamWriterはこの文字列を取得し、相対パスとして使用しています。作業ディレクトリは次のとおりである必要があります。

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

2つは互いに追加されています。簡単に言うと、「file://」を削除する必要があります

于 2013-02-05T05:54:12.073 に答える