Last active
November 21, 2016 21:03
-
-
Save musoftware/3fef908a4d265ac9bb1c33fac6b2cd9e to your computer and use it in GitHub Desktop.
Read Lines from file into Memory,Directly From HDD
This file contains hidden or 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
| var fileRead = System.IO.File.OpenText("test.txt"); | |
| while (fileRead.Peek() != -1) | |
| { | |
| string line = fileRead.ReadLine(); | |
| // here your code | |
| } | |
| fileRead.Close(); |
This file contains hidden or 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
| public static IEnumerable<string> ReadLinesFile(string filename) | |
| { | |
| var fileRead = System.IO.File.OpenText(filename); | |
| while (fileRead.Peek() != -1) | |
| { | |
| string line = fileRead.ReadLine(); | |
| yield return line; | |
| } | |
| fileRead.Close(); | |
| } | |
| /* usage */ | |
| foreach (var line in ReadLinesFile("test.txt")) | |
| { | |
| // here your code | |
| } | |
| /******/ |
This file contains hidden or 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
| foreach (var item in System.IO.File.ReadLines("test.txt")) | |
| { | |
| } |
This file contains hidden or 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
| string[] lines = System.IO.File.ReadAllLines("test.txt", Encoding.UTF8); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment