Writing File Stream C# with Example



Writing File Stream C# with Example

 using System.IO;
using System;

namespace CSharpFilesAndStreams
{
	class WriteToFile 
	{
		static void Main(string[] args) 
		{
			FileStream fout = null;
			try 
			{
				// Open output file.
				fout = new FileStream("test.txt", FileMode.CreateNew);
				
				// Write the alphabet to the file.
				for(char c = 'A'; c <= 'Z'; c++)
				fout.WriteByte((byte) c);
			} 
			catch(IOException exc) 
			{
				Console.WriteLine("I/O Error:\n" + exc.Message);
			} 
			finally 
			{
				if(fout != null) fout.Close();
			}
		}
	}
}	 

0 Comment's

Comment Form

Submit Comment