C# File Create(String)
Description
File Create(String)
Creates or overwrites a file in the
specified path.
Syntax
File.Create(String)
has the following syntax.
public static FileStream Create(
string path
)
Parameters
File.Create(String)
has the following parameters.
path
- The path and name of the file to create.
Returns
File.Create(String)
method returns A FileStream that provides read/write access to the file specified in path.
Example
Creates or overwrites a file in the specified path.
using System;// w ww. j a v a 2 s . co m
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
using (FileStream fs = File.Create(path))
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is from java2s.com.");
fs.Write(info, 0, info.Length);
}
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}