C# Sharp Exercises: Create a file in the disk newly
C# Sharp File Handling: Exercise-1 with Solution
Write a program in C# Sharp to create a blank file in the disk newly.
Sample Solution:-
C# Sharp Code:
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());
}
}
}
Sample Output:
Create a file named mytest.txt in the disk : ------------------------------------------------ A file created with name mytest.txt
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: C# Sharp File Handling Exercises.
Next: Write a program in C# Sharp to remove a file from the disk.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework