Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualbrx

Posted 23 January 2013 - 06:20 AM

Judging by the question, you do not only want to read a line from a file, but also write it, right?

Writing:
TextWriter writer = new StreamWriter("settings.dat");
writer.WriteLine(colorId);
writer.WriteLine(userName);
writer.Close();
Reading:
TextReader reader = new StreamReader("settings.dat");
String colorId = reader.ReadLine();
String userName = reader.ReadLine();
reader.Close();
Note that you also should do some error checking, right now bad things will happen if, for example the file cannot be opened or the file does not have two lines in it...

#1brx

Posted 23 January 2013 - 06:19 AM

Judging by the question, you do not only want to read a line from a file, but also write it, right?

 

Writing:

 

TextWriter writer = new StreamWriter("settings.dat");
writer.WriteLine(colorId);
writer.WriteLine(userName);
writer.close();

Reading:

TextReader reader = new StreamReader("settings.dat");
String colorId = reader.ReadLine();
String userName = reader.ReadLine();
reader.Close();

Note that you also should do some error checking, right now bad things will happen if, for example the file cannot be opened or the file does not have two lines in it...


PARTNERS