Using File Type Members C# with example



You can also use it to check if the file is what it pretends to be(if the extension matches the type).

using System.IO;
using System;

namespace CSharpFilesAndStreams
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("***** Simple I/O with the File Type *****\n");
			string[] myTasks = { "Fix bathroom sink", "Call Dave", "Call Mom and Dad", "Play Xbox 360"};

			// Write out all data to file on C drive.
			File.WriteAllLines(@"C:\tasks.txt", myTasks);

			// Read it all back and print out.
			foreach (string task in File.ReadAllLines(@"C:\tasks.txt"))
			{
				Console.WriteLine("TODO: {0}", task);
			}
		}
	}
}	

0 Comment's

Comment Form