C# FileInfo CreateText
Description
FileInfo CreateText
Creates a StreamWriter that writes
a new text file.
Syntax
FileInfo.CreateText
has the following syntax.
public StreamWriter CreateText()
Returns
FileInfo.CreateText
method returns A new StreamWriter.
Example
The following example demonstrates the CreateText method.
/* w ww . jav a 2 s.c om*/
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
FileInfo fi = new FileInfo(path);
using (StreamWriter sw = fi.CreateText()) {
sw.WriteLine("Hello");
sw.WriteLine("java2s.com");
sw.WriteLine("C#");
}
using (StreamReader sr = fi.OpenText())
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}