Created
September 16, 2019 09:01
-
-
Save gagannn/d92cb7b97fb7155aa6031cabc01013a4 to your computer and use it in GitHub Desktop.
Reading file details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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