0

我在运行我的程序时遇到了这个错误:

mscorlib.dll 中出现“System.IO.IOException”类型的未处理异常

附加信息:文件名、目录名或卷标语法不正确。

到目前为止,我一直无法弄清楚发生了什么。请参阅下面的代码和发生错误的屏幕截图。

发生错误

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);


        }
    }
}
4

1 回答 1

4

.txt\不是您要使用的文件扩展名。

去掉\文件名的末尾。


另外,正如KDecker指出的那样,下面的行在\开头也有一个额外的

string output = @"C:\\Users\Samuel\Documents\Computer_Science\PaDS\output.txt\";
于 2015-12-16T18:27:43.073 回答