Skip to content

Instantly share code, notes, and snippets.

@gagannn
Created September 16, 2019 09:01
Show Gist options
  • Save gagannn/d92cb7b97fb7155aa6031cabc01013a4 to your computer and use it in GitHub Desktop.
Save gagannn/d92cb7b97fb7155aa6031cabc01013a4 to your computer and use it in GitHub Desktop.
Reading file details
using System;
using System.IO;
namespace Lab2_FileReading
{
class Program
{
static void Main(string[] args)
{
string contents = GetText(@"D:\", "abc.txt.txt");
Console.WriteLine("Contents of the files: \n" + contents);
Console.ReadKey(true);
}
private static string GetText(string path, string fileName)
{
var sr = File.OpenText(AppendPathSeparator(path) + fileName);
var text = sr.ReadToEnd();
return text;
string AppendPathSeparator(string filepath)
{
if (!filepath.EndsWith(@"\"))
filepath += @"\";
return filepath;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment