Skip to content

Instantly share code, notes, and snippets.

@justinAurand
Last active December 28, 2015 21:39
Show Gist options
  • Save justinAurand/7565974 to your computer and use it in GitHub Desktop.
Save justinAurand/7565974 to your computer and use it in GitHub Desktop.
Transfer text, line by line, from one text file to another. Good for programmatic text manipulation.
using System;
using System.IO;
class TextTransfer
{
static void Main()
{
const string ReadingFilePath = @"C:\stuff.txt";
const string WritingFilePath = @"C:\stuff2.txt";
const bool AppendToFile = false;
string line = String.Empty;
using (var streamReader = new StreamReader(ReadingFilePath))
using (var streamWriter = new StreamWriter(WritingFilePath, AppendToFile))
{
while ((line = streamReader.ReadLine()) != null)
streamWriter.WriteLine(line);
}
Console.WriteLine("Completed.");
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment