How can I read file line. For example I create file settings.dat and i want to store two lines in it, color id, and username. How do i need to do. I tried to google but it was not worth it. :(
How to read file line
Judging by the question, you do not only want to read a line from a file, but also write it, right?
Writing:
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...
So first string will read first line, and the second string will read second line. Am i right?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement