Byte-Oriented: Write to a file

image_pdfimage_print

using System;
using System.IO;
class WriteToFile {
public static void Main(string[] args) {
FileStream fout;

try {
fout = new FileStream(“test.txt”, FileMode.Create);
} catch(IOException exc) {
Console.WriteLine(exc.Message + ”
Error Opening Output File”);
return;
}

// Write the alphabet to the file.
try {
for(char c = 'A'; c <= 'Z'; c++) fout.WriteByte((byte) c); } catch(IOException exc) { Console.WriteLine(exc.Message + "File Error"); } fout.Close(); } } [/csharp]

This entry was posted in File Stream. Bookmark the permalink.