programming-examples/c-sharp/Files/C# Program to Create a File.cs
2019-11-15 12:59:38 +01:00

30 lines
690 B
C#

/*
* C# Program to Create a File
*/
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();
}
}
/*
File is Created