Created
August 17, 2023 02:38
-
-
Save joe-oli/9ebc8b0dfbfa13b726605748245a912a to your computer and use it in GitHub Desktop.
Read / Write Text files
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
//Good for small files | |
using System; | |
using System.IO; | |
public class Example | |
{ | |
public static void Main() | |
{ | |
string fileName = @"C:\some\path\file.txt"; | |
using (StreamReader streamReader = File.OpenText(fileName)) | |
{ | |
string text = streamReader.ReadToEnd(); | |
string[] lines = text.Split(Environment.NewLine); | |
foreach (string line in lines) { | |
Console.WriteLine(line); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment