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. ![]()
#1 Members - Reputation: 117
Posted 23 January 2013 - 06:06 AM
Project Download Link: http://www.mediafire...zjahgz0b4ba70ep 0.01a Version!
My Project VCOS: http://www.gamedev.n...os-development/
0.01b is coming with much more updates! Check My Blog for TODO list ![]()
My Blog: http://www.thescriptan.blogspot.com
#2 Members - Reputation: 443
Posted 23 January 2013 - 06:19 AM
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...
Edited by brx, 23 January 2013 - 06:20 AM.
#3 Members - Reputation: 117
Posted 23 January 2013 - 06:23 AM
So first string will read first line, and the second string will read second line. Am i right?
Project Download Link: http://www.mediafire...zjahgz0b4ba70ep 0.01a Version!
My Project VCOS: http://www.gamedev.n...os-development/
0.01b is coming with much more updates! Check My Blog for TODO list ![]()
My Blog: http://www.thescriptan.blogspot.com
#4 Members - Reputation: 117
Posted 23 January 2013 - 06:30 AM
Embedded statement cannot be a declaration or labeled statement. what to do?
Project Download Link: http://www.mediafire...zjahgz0b4ba70ep 0.01a Version!
My Project VCOS: http://www.gamedev.n...os-development/
0.01b is coming with much more updates! Check My Blog for TODO list ![]()
My Blog: http://www.thescriptan.blogspot.com
#6 Members - Reputation: 117
Posted 23 January 2013 - 06:47 AM
while (File.Exists("Settings.dat"))
{
options.username = reader.ReadLine();
Console.WriteLine("User: " + options.username);
reader.Close();
}
What is wrong in here?
Edited by TheScriptan, 23 January 2013 - 06:52 AM.
Project Download Link: http://www.mediafire...zjahgz0b4ba70ep 0.01a Version!
My Project VCOS: http://www.gamedev.n...os-development/
0.01b is coming with much more updates! Check My Blog for TODO list ![]()
My Blog: http://www.thescriptan.blogspot.com
#7 Members - Reputation: 117
Posted 23 January 2013 - 07:07 AM
Okay i finally fixed it
Project Download Link: http://www.mediafire...zjahgz0b4ba70ep 0.01a Version!
My Project VCOS: http://www.gamedev.n...os-development/
0.01b is coming with much more updates! Check My Blog for TODO list ![]()
My Blog: http://www.thescriptan.blogspot.com







