0

hey....i got some problem in ReadLines method

  string filePath = @"c:\Users\Fish\Desktop\fyp-coding\Data.txt";
                    string line;

                 if (File.Exists(filePath))
                    {
                        StreamReader file = null;
                        try
                        {
                            file = new StreamReader(filePath);



                            while ((line= file.ReadLine())!= null)
                            {
                                textBox7.Text = line;

                            }

                        }

                        finally
                        {
                            if (file != null)
                            file.Close();
                        }

                    }

When i use this coding...it only show the last line to me. I want show the previous line, how to do it?

Edited by mike_2000_17: Fixed formatting

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Momerath
0
string filePath = @"c:\Users\Fish\Desktop\fyp-coding\Data.txt";
String[] myLines = File.ReadAllLines(filePath);
textBox7.Text = myLines[myLines.Length - 2];
0

what is different between readLine, readAllLine and readToEnd...?

Edited by Kath_Fish: n/a

0

ReadLine gets one line from the file
ReadAllLines reads all the lines and returns an array of strings.
ReadToEnd reads the entire file returning it as one string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.