Ive got this text file Im trying to read from. Its located in my resources folder in microsoft visual studio. Im trying to access that text file so I can parse the text from that file to an integer and store it in my integer array called Armor[,] .The contents of the text file is a 12x11 chart of numbers which I would like to parse to an integer and store into the 2D Armor[,] array. Here are the contents of the text file:
When I run the program I get an error saying:
Value cannot be null.
Parameter name: path
The error that microsoft visual studio's throwing is because of the line:
[source]StreamReader armorStream = new StreamReader(Resources.Armor);[/source]
[source]
//namespace used do directly access Resource.FileName
using TurfBattles.Properties;
public void LoadArmor()
{
//Create a variable for storing the armor defense values
int[,] Armor = new int[12, 11];
//Create a string variable for storing the stream readers input
string myString = new string();
int Row = 0;
//Create a stream reader for reading the Armor.txt file
StreamReader armorStream = new StreamReader(Resources.Armor);
//While the stream reader is able to read the next line
//do this:
while ((myString = armorStream.ReadLine()) != null)
{
//Loop through each value of the myStringSplit array
for (int Column = 0; Column < 11; Column++)
{
//This splits the text up and stores it into an array of strings
//It also stores the white spaces into a character array
string[] myStringSplit = myString.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
//Store the current value of myStringSplit into the Armor Array
Armor[Row, Column] = int.Parse(myStringSplit[Column]);
}
Console.WriteLine();
Row++;
}
armorStream.Close();
Console.ReadKey();
}
[/source]