Saturday, 2 December 2017

C# Program to Create a File


Code:

using System;
using System.IO;
using System.Text;
class Test
{
    public static void Main()
    {
        string textpath = @"c:\sri\test.txt";
        using (FileStream fs = File.Create(textpath))
        {
            Byte[] info = new UTF8Encoding(true).GetBytes("File is Created");
            fs.Write(info, 0, info.Length);
        } 
        using (StreamReader sr = File.OpenText(textpath))
        {
            string s = "";
            while ((s = sr.ReadLine()) != null)
            {
                Console.WriteLine(s);
            }
        }
        Console.Read();
    }
}


Output:

File is Created



More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...