Get File Content - CSharp System.IO

CSharp examples for System.IO:Text File

Description

Get File Content

Demo Code


using System.IO ;
using System.Windows.Forms ;
using System;/*from  w w w  .ja  v  a  2s. c om*/

public class Main{
 
      public static string GetFileContent(string file_path)
      {
         if(! File.Exists(file_path))
         {
            return null ;
         }
         
         StreamReader reader = new StreamReader(file_path ,System.Text.Encoding.Default ) ;
         string content = reader.ReadToEnd() ;
         reader.Close() ;

         return content ;
      }
}

Related Tutorials