Reads a line of characters from the current stream and returns the data as a string. : Stream « File Stream « C# / C Sharp






Reads a line of characters from the current stream and returns the data as a string.

   

using System;
using System.IO;

class Test 
{
  
    public static void Main() 
    {
            string path = @"c:\temp\MyTest.txt";
            if (File.Exists(path)) 
            {
                File.Delete(path);
            }

            using (StreamWriter sw = new StreamWriter(path)) 
            {
                sw.WriteLine("This");
                sw.WriteLine("is some text");
                sw.WriteLine("to test");
                sw.WriteLine("Reading");
            }

            using (StreamReader sr = new StreamReader(path)) 
            {
                while (sr.Peek() >= 0) 
                {
                    Console.WriteLine(sr.ReadLine());
                }
            }
    }
}

   
    
    
  








Related examples in the same category

1.Stream.CanRead indicates whether the current stream supports reading.
2.Stream.CanWrite Property indicates whether the current stream supports writing.
3.Stream.CopyTo reads all the bytes from the current stream and writes them to the destination stream.
4.Stream.Read reads a sequence of bytes and advances the position
5.Create StreamWriter class for the specified stream, using the specified encoding and the default buffer size.
6.Create StreamWriter from FileStream
7.Create StreamWriter with encoding
8.Create StreamWriter from file name
9.UTF8 encoding StreamWriter
10.Create UTF8 encoding StreamWriter from File name
11.Set StreamWriter buffer size
12.Writes a subarray of characters to the stream.
13.Create a new instance of the StreamReader class for the specified stream.
14.Gets the current character encoding that the current StreamReader object is using.
15.Returns the next available character but does not consume it.
16.Reads a maximum of count characters from the current stream into buffer, beginning at index.
17.Reads the next character from the input stream and advances the character position by one character.
18.Read a single character
19.Reads the stream from the current position to the end of the stream.
20.Copy Stream
21.Copy one Stream to another Stream
22.Authentication Stream
23.Outputs data from a read stream to a newly created file