3

コンピュータのデスクトップに保存されている xxx.txt ファイルを開きたいのですが、プログラムで

errorパーサー エラー エスケープ シーケンス '\D' を認識できません。私はのパスを与えようとしています

"C:\Documents and Settings\user\Desktop\xxx.txt"としてファイルします。

私は正しい方法でパスを与えていますか、それともそれを与える他の方法はありますか

4

5 に答える 5

25

\C#文字列のエスケープ文字です。改行(\n)などの特殊文字に使用されます。リテラルを書くには、\別のリテラルで引用する必要があります\

string myFileName = "C:\\Documents and Settings\\user\\Desktop\\xxx.txt";

別の方法は、文字を含む文字列の引用符を無効にすること@です。

string myFileName = @"C:\Documents and Settings\user\Desktop\xxx.txt";
于 2012-04-10T05:44:07.550 に答える
12

次のパスを使用します。

string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "xxx.txt");
于 2012-04-10T05:44:46.017 に答える
2

I had to access a file in my project, so the folder 'lib' which contains all the files i need, i placed this folder in the 'bin' folder of my project, and now i can access any file i need from lib folder. In code path i used is as follows:

StreamReader sr = new StreamReader("..\\lib\\myFile.src");

Works well! :)

于 2017-08-29T06:35:33.613 に答える
1

パスをに変更しますC:\\Documents and Settings\\user\\Desktop\\xxx.txt

于 2012-04-10T05:44:24.493 に答える
-6

C:\ Documents and Settings \ user \ Desktop/xxx.txtを使用してみてください

C:\ Documents and Settings \ user \ Desktop\xxx.txtの代わりに

于 2012-04-10T05:45:46.803 に答える