File Type C# with Example



File Type C# with Example

 using System.IO;
using System;

namespace CSharpFilesAndStreams
{
	class Program
	{
		static void Main(string[] args)
		{
			// Obtain FileStream object via File.Create().
			using(FileStream fs = File.Create(@"C:\Test.dat")){}

			// Obtain FileStream object via File.Open().
			using(FileStream fs2 = File.Open(@"C:\Test2.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)){}

			// Get a FileStream object with read-only permissions.
			using(FileStream readOnlyStream = File.OpenRead(@"Test3.dat")){}

			// Get a FileStream object with write-only permissions.
			using(FileStream writeOnlyStream = File.OpenWrite(@"Test4.dat")){}

			// Get a StreamReader object.
			using(StreamReader sreader = File.OpenText(@"C:\boot.ini")){}

			// Get some StreamWriters.
			using(StreamWriter swriter = File.CreateText(@"C:\Test6.txt")){}
			using(StreamWriter swriterAppend = File.AppendText(@"C:\FinalTest.txt")){}
		}
	}
}	 

0 Comment's

Comment Form