Problem solve Get help with specific problems with your technologies, process and projects.

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

Dig Deeper on C# programming language

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

SearchCloudApplications

Close