Writing to a File using System.IO
Author : Pallavi Chand
Level : Beginner
In this article we will see how we can write data to a file from another file.
Code
using System;
using System.IO;
class AppendText
{
public static void Main(String[] args)
{
//Append the text from InputFile.txt to this file.
TextWriter outfile= File.AppendText("c:/CopytoFile.txt");
//Append text from this file to CopytoFile.txt.
TextReader infile = File.OpenText("c:/InFile.txt");
String Str;
while((Str = infile.ReadLine())!=null)
outfile.WriteLine(Str);
infile.Close();
outfile.Close();
}
}
Last Updated:Thursday, September 02, 2010By:alferoSource#
with your OpenID.
If you do not know what OpenID is,