System.IO 异常未处理
System.IO Exception Unhandled
我在 运行 我的程序时一直遇到这个错误:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The filename, directory name, or volume label syntax is incorrect.
到目前为止,我一直无法弄清楚发生了什么。请参阅下面的代码和发生错误的屏幕截图。
using System;
using System.IO;
using System.Linq;
namespace CipherDecoder
{
class Program
{
static void Main(string[] args)
{
string fileText = @"C:\Users\Samuel\Documents\Computer_Science\PaDS\caesarShiftEncodedText.txt\";
string cipherText = File.ReadAllText(fileText);
string textPre = "";
string output = @"C:\Users\Samuel\Documents\Computer_Science\PaDS\output.txt\";
char[] cipherChars = new char[691];
int[] charactersAsInts = File.ReadAllText(fileText).Select(chr => (int)chr).ToArray();
Console.WriteLine("Process started");
for(int i = 0; i < charactersAsInts.Length; i++)
{
charactersAsInts[i] = charactersAsInts[i] - 5;
}
for(int j = 0; j < charactersAsInts.Length; j++)
{
if(charactersAsInts[j] == 60)
{
textPre = textPre + "A";
}
if (charactersAsInts[j] == 61)
{
textPre = textPre + "B";
}
if (charactersAsInts[j] == 62)
{
textPre = textPre + "C";
}
if (charactersAsInts[j] == 63)
{
textPre = textPre + "D";
}
if (charactersAsInts[j] == 64)
{
textPre = textPre + "E";
}
if (charactersAsInts[j] == 65)
{
textPre = textPre + "F";
}
if (charactersAsInts[j] == 66)
{
textPre = textPre + "G";
}
if (charactersAsInts[j] == 67)
{
textPre = textPre + "H";
}
if (charactersAsInts[j] == 68)
{
textPre = textPre + "I";
}
if (charactersAsInts[j] == 69)
{
textPre = textPre + "J";
}
if (charactersAsInts[j] == 70)
{
textPre = textPre + "K";
}
if (charactersAsInts[j] == 71)
{
textPre = textPre + "L";
}
if (charactersAsInts[j] == 72)
{
textPre = textPre + "M";
}
if (charactersAsInts[j] == 73)
{
textPre = textPre + "N";
}
if (charactersAsInts[j] == 74)
{
textPre = textPre + "O";
}
if (charactersAsInts[j] == 75)
{
textPre = textPre + "P";
}
if (charactersAsInts[j] == 76)
{
textPre = textPre + "Q";
}
if (charactersAsInts[j] == 77)
{
textPre = textPre + "R";
}
if (charactersAsInts[j] == 78)
{
textPre = textPre + "S";
}
if (charactersAsInts[j] == 79)
{
textPre = textPre + "T";
}
if (charactersAsInts[j] == 80)
{
textPre = textPre + "U";
}
if (charactersAsInts[j] == 81)
{
textPre = textPre + "V";
}
if (charactersAsInts[j] == 82)
{
textPre = textPre + "W";
}
if (charactersAsInts[j] == 83)
{
textPre = textPre + "X";
}
if (charactersAsInts[j] == 84)
{
textPre = textPre + "Y";
}
if (charactersAsInts[j] == 85)
{
textPre = textPre + "Z";
}
if(charactersAsInts[j] == 27)
{
textPre = textPre + " ";
}
}
Console.WriteLine("{0}", textPre);
}
}
}
.txt\
不是您要使用的文件扩展名。
去掉文件名末尾的 \
。
另外,正如 KDecker 指出的那样,下面一行的开头也有一个额外的 \
string output = @"C:\Users\Samuel\Documents\Computer_Science\PaDS\output.txt\";
我在 运行 我的程序时一直遇到这个错误:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The filename, directory name, or volume label syntax is incorrect.
到目前为止,我一直无法弄清楚发生了什么。请参阅下面的代码和发生错误的屏幕截图。
using System;
using System.IO;
using System.Linq;
namespace CipherDecoder
{
class Program
{
static void Main(string[] args)
{
string fileText = @"C:\Users\Samuel\Documents\Computer_Science\PaDS\caesarShiftEncodedText.txt\";
string cipherText = File.ReadAllText(fileText);
string textPre = "";
string output = @"C:\Users\Samuel\Documents\Computer_Science\PaDS\output.txt\";
char[] cipherChars = new char[691];
int[] charactersAsInts = File.ReadAllText(fileText).Select(chr => (int)chr).ToArray();
Console.WriteLine("Process started");
for(int i = 0; i < charactersAsInts.Length; i++)
{
charactersAsInts[i] = charactersAsInts[i] - 5;
}
for(int j = 0; j < charactersAsInts.Length; j++)
{
if(charactersAsInts[j] == 60)
{
textPre = textPre + "A";
}
if (charactersAsInts[j] == 61)
{
textPre = textPre + "B";
}
if (charactersAsInts[j] == 62)
{
textPre = textPre + "C";
}
if (charactersAsInts[j] == 63)
{
textPre = textPre + "D";
}
if (charactersAsInts[j] == 64)
{
textPre = textPre + "E";
}
if (charactersAsInts[j] == 65)
{
textPre = textPre + "F";
}
if (charactersAsInts[j] == 66)
{
textPre = textPre + "G";
}
if (charactersAsInts[j] == 67)
{
textPre = textPre + "H";
}
if (charactersAsInts[j] == 68)
{
textPre = textPre + "I";
}
if (charactersAsInts[j] == 69)
{
textPre = textPre + "J";
}
if (charactersAsInts[j] == 70)
{
textPre = textPre + "K";
}
if (charactersAsInts[j] == 71)
{
textPre = textPre + "L";
}
if (charactersAsInts[j] == 72)
{
textPre = textPre + "M";
}
if (charactersAsInts[j] == 73)
{
textPre = textPre + "N";
}
if (charactersAsInts[j] == 74)
{
textPre = textPre + "O";
}
if (charactersAsInts[j] == 75)
{
textPre = textPre + "P";
}
if (charactersAsInts[j] == 76)
{
textPre = textPre + "Q";
}
if (charactersAsInts[j] == 77)
{
textPre = textPre + "R";
}
if (charactersAsInts[j] == 78)
{
textPre = textPre + "S";
}
if (charactersAsInts[j] == 79)
{
textPre = textPre + "T";
}
if (charactersAsInts[j] == 80)
{
textPre = textPre + "U";
}
if (charactersAsInts[j] == 81)
{
textPre = textPre + "V";
}
if (charactersAsInts[j] == 82)
{
textPre = textPre + "W";
}
if (charactersAsInts[j] == 83)
{
textPre = textPre + "X";
}
if (charactersAsInts[j] == 84)
{
textPre = textPre + "Y";
}
if (charactersAsInts[j] == 85)
{
textPre = textPre + "Z";
}
if(charactersAsInts[j] == 27)
{
textPre = textPre + " ";
}
}
Console.WriteLine("{0}", textPre);
}
}
}
.txt\
不是您要使用的文件扩展名。
去掉文件名末尾的 \
。
另外,正如 KDecker 指出的那样,下面一行的开头也有一个额外的 \
string output = @"C:\Users\Samuel\Documents\Computer_Science\PaDS\output.txt\";