[Assistance] System.IO.IOException occurred in mscorlib.dll

Apr 12 2015 9:35 AM
Hi
i am having trouble with this error in my C# console application, whenever i enter an invalid message the console kicks up this error message and i do not know how to fix it. My program is a simple one, it is designed to record any incorrect number plates and write them to a file. Please excuse this as it is my first question on a website like this. I will post my code and the error below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
StreamWriter File = new StreamWriter(@"E:/CarsDatabase.txt", true);
Console.WriteLine("enter number plate");
string input = Console.ReadLine();
string registration = input;

char[] registrationnumberchars = registration.ToCharArray();
bool result = Char.IsLetter(registrationnumberchars[0]);
Console.WriteLine(result);
if (result != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}

bool result1 = Char.IsLetter(registrationnumberchars[1]);
Console.WriteLine(result1);
if (result1 != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}
bool result2 = Char.IsNumber(registrationnumberchars[2]);
Console.WriteLine(result2);
if (result2 != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}
bool result3 = Char.IsNumber(registrationnumberchars[3]);
Console.WriteLine(result3);
if (result3 != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}
bool result4 = Char.IsLetter(registrationnumberchars[4]);
Console.WriteLine(result4);
if (result4 != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}
bool result5 = Char.IsLetter(registrationnumberchars[5]);
Console.WriteLine(result5);
if (result5 != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}
bool result6 = Char.IsLetter(registrationnumberchars[6]);
Console.WriteLine(result6);
if (result6 != true)
{
StreamWriter file = new StreamWriter(@"E:/CarsDatabase.txt", true);
file.WriteLine(registrationnumberchars);
file.Close();
Console.WriteLine("adding false plate to database");
}


Console.ReadLine();
}
}
}

 

Answers (2)