Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to read file line


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 TheScriptan   Members   -  Reputation: 207

Like
0Likes
Like

Posted 23 January 2013 - 06:06 AM

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. :(


Check out my blog or twitter for news how I am doing in the project "Learn Programming in 2 Years!". You can follow my progress, and help me! :)

 

My Projects:

              "Learn Programming In 2 Years"

              "Windows Tutorials"

              "Ubuntu Tutorials"

 

My Games:

              Moving@ IndieDB: http://www.indiedb.com/games/moving-rl

 

My Links:

              My Blog: http://www.thescriptan.blogspot.com

              My Twitter: https://twitter.com/TheScriptan


Sponsor:

#2 brx   Members   -  Reputation: 695

Like
3Likes
Like

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...

Edited by brx, 23 January 2013 - 06:20 AM.


#3 TheScriptan   Members   -  Reputation: 207

Like
0Likes
Like

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?


Check out my blog or twitter for news how I am doing in the project "Learn Programming in 2 Years!". You can follow my progress, and help me! :)

 

My Projects:

              "Learn Programming In 2 Years"

              "Windows Tutorials"

              "Ubuntu Tutorials"

 

My Games:

              Moving@ IndieDB: http://www.indiedb.com/games/moving-rl

 

My Links:

              My Blog: http://www.thescriptan.blogspot.com

              My Twitter: https://twitter.com/TheScriptan


#4 TheScriptan   Members   -  Reputation: 207

Like
0Likes
Like

Posted 23 January 2013 - 06:30 AM

Embedded statement cannot be a declaration or labeled statement. what to do?


Check out my blog or twitter for news how I am doing in the project "Learn Programming in 2 Years!". You can follow my progress, and help me! :)

 

My Projects:

              "Learn Programming In 2 Years"

              "Windows Tutorials"

              "Ubuntu Tutorials"

 

My Games:

              Moving@ IndieDB: http://www.indiedb.com/games/moving-rl

 

My Links:

              My Blog: http://www.thescriptan.blogspot.com

              My Twitter: https://twitter.com/TheScriptan


#5 pulpfist   Members   -  Reputation: 528

Like
0Likes
Like

Posted 23 January 2013 - 06:36 AM

Maybe this is the problem

http://forums.asp.net/t/1239769.aspx/1



#6 TheScriptan   Members   -  Reputation: 207

Like
0Likes
Like

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.

Check out my blog or twitter for news how I am doing in the project "Learn Programming in 2 Years!". You can follow my progress, and help me! :)

 

My Projects:

              "Learn Programming In 2 Years"

              "Windows Tutorials"

              "Ubuntu Tutorials"

 

My Games:

              Moving@ IndieDB: http://www.indiedb.com/games/moving-rl

 

My Links:

              My Blog: http://www.thescriptan.blogspot.com

              My Twitter: https://twitter.com/TheScriptan


#7 TheScriptan   Members   -  Reputation: 207

Like
0Likes
Like

Posted 23 January 2013 - 07:07 AM

Okay i finally fixed it


Check out my blog or twitter for news how I am doing in the project "Learn Programming in 2 Years!". You can follow my progress, and help me! :)

 

My Projects:

              "Learn Programming In 2 Years"

              "Windows Tutorials"

              "Ubuntu Tutorials"

 

My Games:

              Moving@ IndieDB: http://www.indiedb.com/games/moving-rl

 

My Links:

              My Blog: http://www.thescriptan.blogspot.com

              My Twitter: https://twitter.com/TheScriptan


#8 Inuyashakagome16   Members   -  Reputation: 835

Like
0Likes
Like

Posted 23 January 2013 - 07:22 AM

Well what was your resolve? Like what was wrong with the code?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS