File Input Output

Opens a file and prints data of that file on CommanLine...


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace OpenFile
{
class Program
{
static void Main(string[] args)
{
try
{
FileStream fs = new FileStream("D:\\MyFiles\\first.txt", FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs);
string str = sr.ReadToEnd();
Console.WriteLine("The File has data as follows...\n");
Console.WriteLine(str);
sr.Close();
fs.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: