Q:

Write a program in C# Sharp to create a blank file in the disk newly

0

Write a program in C# Sharp to create a blank file in the disk newly. 
Expected Output :

 A file created with name mytest.txt 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.IO;
using System.Text;

class filexercise1
{
    public static void Main()
    {
        string fileName = @"mytest.txt";
        try
        {
			Console.Write("\n\n Create a file named mytest.txt in the disk :\n");
			Console.Write("------------------------------------------------\n");
            // Create the file.
            using (FileStream fileStr = File.Create(fileName))
            {
                Console.WriteLine(" A file created with name mytest.txt\n\n");
            }
        }
        catch (Exception MyExcep)
        {
            Console.WriteLine(MyExcep.ToString());
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now