Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Created August 17, 2023 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joe-oli/9ebc8b0dfbfa13b726605748245a912a to your computer and use it in GitHub Desktop.
Save joe-oli/9ebc8b0dfbfa13b726605748245a912a to your computer and use it in GitHub Desktop.
Read / Write Text files
//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