Read text file with auto close statement - CSharp File IO

CSharp examples for File IO:Text File

Description

Read text file with auto close statement

Demo Code

using System;/*from ww w  .  j  a  v a 2 s  .c  o  m*/
using System.IO;
class Program
{
   static void Main(string[] args)
   {
      using (StreamReader reader = new StreamReader("test-file.txt"))
      {
         string contents = reader.ReadToEnd();
         Console.WriteLine("File contents:");
         Console.WriteLine(contents);
      }
   }
}

Result


Related Tutorials