Writing to a file using System.IO

Here's how you can write data to a file from another file in C#.

Please let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like

to share? Submit it here!


You probably know how data can be read from a file. Here's how you can write data to a file from another file in C#:


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();
}
}


Source: DotNetExtreme.com
This was first published in March 2003

Dig deeper on C# programming language

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close