我刚刚测试一些code的那一刻,尽管调用StartRemoveDuplicate(当它编译)抛出一个异常时,抱怨非法字符:
我的code是如下:
类节目
{
静态无效的主要(字串[] args)
{
的foreach(在System.IO.File.ReadAllLines字符串EXENAME(的test.txt))
{
的Process.Start(TEST.EXE,\+ EXENAME +\)WaitForExit()。
}
StartRemoveDuplicate();
}
私有静态无效RemoveDuplicate(字符串sourceFilePath,串destinationFilePath)
{
VAR readlines方法= File.ReadAllLines(sourceFilePath,Encoding.Default);
File.WriteAllLines(destinationFilePath,readLines.Distinct()的ToArray(),Encoding.Default。);
}
私有静态无效StartRemoveDuplicate()
{
RemoveDuplicate(C:\ test.txt的,C:\的test2.txt);
}
}
解决方案
尝试串像以前一样使用@:
@C:\ test.txt的
或escpe的\卡拉科特
C:\\的test.txt
I am just testing some code at the moment, although when calling the StartRemoveDuplicate (when its compiled) an Exception is thrown, complaining about illegal characters:
My code is as follows:
class Program
{
static void Main(string[] args)
{
foreach (string exename in System.IO.File.ReadAllLines("test.txt"))
{
Process.Start("test.exe", "\"" + exename + "\"").WaitForExit();
}
StartRemoveDuplicate();
}
private static void RemoveDuplicate(string sourceFilePath, string destinationFilePath)
{
var readLines = File.ReadAllLines(sourceFilePath, Encoding.Default);
File.WriteAllLines(destinationFilePath, readLines.Distinct().ToArray(), Encoding.Default);
}
private static void StartRemoveDuplicate()
{
RemoveDuplicate("C:\test.txt", "C:\test2.txt");
}
}
解决方案
Try to use @ before the string like :
@"C:\test.txt"
or to escpe the "\" caracter
"C:\\test.txt"