Last active
August 5, 2020 17:37
-
-
Save nanwang2016/bb87644534a44b457250409b147d9eda to your computer and use it in GitHub Desktop.
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.IO; | |
namespace TestFile | |
{ | |
class Program | |
{ | |
//The text file's path is stored in 'filename' | |
static string filename = @"C:\Users\Nan\source\repos\Example.txt"; | |
static void Main(string[] args) | |
{ | |
static void ReadFile() | |
{ | |
FileStream fs = null; | |
try | |
{ | |
fs = new FileStream(filename, FileMode.Open, FileAccess.Read); | |
var b1 = fs.ReadByte(); | |
var c1 = (char)b1; | |
} | |
finally | |
{ | |
//File is closed | |
fs?.Close(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment