C# File Create(String, Int32, FileOptions, FileSecurity)
Description
File Create(String, Int32, FileOptions, FileSecurity)
Creates
or overwrites the specified file with the specified buffer size, file options,
and file security.
Syntax
File.Create(String, Int32, FileOptions, FileSecurity)
has the following syntax.
public static FileStream Create(
string path,// w ww .j av a 2 s.co m
int bufferSize,
FileOptions options,
FileSecurity fileSecurity
)
Parameters
File.Create(String, Int32, FileOptions, FileSecurity)
has the following parameters.
path
- The name of the file.bufferSize
- The number of bytes buffered for reads and writes to the file.options
- One of the FileOptions values that describes how to create or overwrite the file.fileSecurity
- One of the FileSecurity values that determines the access control and audit security for the file.
Returns
File.Create(String, Int32, FileOptions, FileSecurity)
method returns A new file with the specified buffer size, file options, and file security.
Example
using System;//from www . j ava 2 s. co m
using System.IO;
using System.Text;
using System.Security.AccessControl;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
using (FileStream fs = File.Create(path, 1024, FileOptions.RandomAccess, new FileSecurity()))
{
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);
}
}
}
}