C# File Create(String, Int32)
Description
File Create(String, Int32)
Creates or overwrites the
specified file.
Syntax
File.Create(String, Int32)
has the following syntax.
public static FileStream Create(
string path,
int bufferSize
)
Parameters
File.Create(String, Int32)
has the following parameters.
path
- The name of the file.bufferSize
- The number of bytes buffered for reads and writes to the file.
Returns
File.Create(String, Int32)
method returns A FileStream with the specified buffer size that provides read/write access
to the file specified in path.
Example
The following example creates a file with the specified buffer size.
/* w ww . j a va 2s.com*/
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
using (FileStream fs = File.Create(path, 1024))
{
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);
}
}
}
}