我想打开一个保存在我的电脑桌面上的xxx.txt文件,但该程序给出了一个
错误分析器错误无法识别的转义序列'\ D'.我试图给出的道路
文件为"C:\ Documents and Settings\user\Desktop\xxx.txt".
我是以正确的方式给出路径还是有任何其他方式来给它
And*_*bel 17
\是C#字符串中的转义字符.它用于特殊字符,例如换行符(\n).要写一个文字,\你必须引用另一个\:
string myFileName = "C:\\Documents and Settings\\user\\Desktop\\xxx.txt";
Run Code Online (Sandbox Code Playgroud)
另一种方法是禁用带@字符的字符串的引用:
string myFileName = @"C:\Documents and Settings\user\Desktop\xxx.txt";
Run Code Online (Sandbox Code Playgroud)
ion*_*den 12
使用此路径:
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "xxx.txt");
Run Code Online (Sandbox Code Playgroud)