❔ Reading data from a text file
I have only just started trying to work with txt files and was wondering if anyone could help me and try to fix my code!
string fileName = "Cookies.txt";
TextWriter textFileWrite = new StreamWriter(fileName);
TextReader textFileRead = new StreamReader(fileName);
string data;
if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) == null)
{
Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine();
textFileWrite.WriteLine(choice);
}
if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) != null)
{
Console.WriteLine("You selected: " + data);
Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine();
textFileWrite.WriteLine(choice);
}
textFileRead.Close();
textFileWrite.Close();
string fileName = "Cookies.txt";
TextWriter textFileWrite = new StreamWriter(fileName);
TextReader textFileRead = new StreamReader(fileName);
string data;
if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) == null)
{
Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine();
textFileWrite.WriteLine(choice);
}
if ((data = textFileRead.ReadLine().Skip(1).Take(1).First().ToString()) != null)
{
Console.WriteLine("You selected: " + data);
Console.WriteLine("Would you like to save 'dark' or 'light' theme..."); string choice = Console.ReadLine();
textFileWrite.WriteLine(choice);
}
textFileRead.Close();
textFileWrite.Close();