Reading and Writing Data – C# – part 3 (Text Files)

Text Files

StreamReader, StreamWriter, main methods:

  • ReadLine(), WriteLine()
FileInfo sourceFile = new FileInfo(@"C:\test\someFile.cs");

StreamReader reader = sourceFile.OpenText();

/* The second parameter is the Boolean argument append. If the file already exists, true will cause
the new data to be appended to the end of the file, and false will casue the file to be overwritten. */
StreamWriter writer = new StreamWriter(@"C:\test\someFile.bak", false);

string text;

   text = reader.ReadLine();
} while (text != null);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s