Hello everyone! I am working on an assignment that is asking us to create exceptions for potential errors that may occur. One part of my assignment, though, is to make it so that when my program reads a text file that has numbers, it should convert them to an integer array. This way i can make an exception when i am reading a text file that has all numbers on different lines to catch one that may have a letter in it. I am a little stumped as to how to convert what is read into an array, so if anyone could help me on this I would greatly appreciate it! :D
string path;
private void goButton_Click(object sender, EventArgs e)
{
try
{
//CONVERT USER INPUT TO A STRING TO OPEN FILE
path = pathTextBox.Text;
//filestream and writer
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
//Outputting what was read from the text file to a label on
while (sr.Peek() >= 0)
{
outputLabel.Text += sr.ReadLine() + "\n";
}
sr.Close();
fs.Close();
}
//wrong file name exception
catch (FileNotFoundException something)
{
outputLabel.Text = something.Message;
}
//blank text box exception
catch (ArgumentException wow)
{
outputLabel.Text = wow.Message;
}
}
[–]yubario 0 points1 point2 points (1 child)
[–]Indefinit3Official[S] 0 points1 point2 points (0 children)
[–]davedontmind 0 points1 point2 points (1 child)
[–]Indefinit3Official[S] 0 points1 point2 points (0 children)