我正在制作一个简单的命令程序,在尝试创建目录时,我收到错误,路径中有无效字符,我猜NetworkStream添加了不可见字符?
代码:
Console.WriteLine(">> Recieved: " + Encoding.ASCII.GetString(data, 0, data.Length));
byte[] back = null;
if (Encoding.ASCII.GetString(data, 0, data.Length).Contains("cd "))
{
try
{
back = Encoding.UTF8.GetBytes(">> Created Directory");
stream.Write(back, 0, back.Length);
string dir = Encoding.ASCII.GetString(data, 0, data.Length).Replace("cd ", "");
Directory.CreateDirectory(dir);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
精确错误:System.Argument异常,路径处的非法字符
将dir.ToCharArray()
放入调试器监视表达式中。现在,您将看到各个字符代码,包括不可打印的字符代码,如0。