Text File Read - CSharp System.IO

CSharp examples for System.IO:Text File

Description

Text File Read

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.IO;// www  .  j  ava  2 s .c o m
using System.Collections.Generic;
using System;

public class Main{
        public static string FileRead(string filePath)
        {
            string ret = "";

            try
            {
                string tmpLine;
                StreamReader sr = new StreamReader(filePath, true);
                {
                    tmpLine = sr.ReadToEnd();
                    ret += tmpLine;
                }
                sr.Close();
            }
            catch (FileNotFoundException e)
            {
                //throw e;
            }
            catch (IOException e)
            {

            }
            return ret;
        }
}

Related Tutorials