C# File Create(String, Int32, FileOptions)

Description

File Create(String, Int32, FileOptions) Creates or overwrites the specified file, specifying a buffer size and a FileOptions value that describes how to create or overwrite the file.

Syntax

File.Create(String, Int32, FileOptions) has the following syntax.


public static FileStream Create(
  string path,/*from www .j  a va  2 s . co  m*/
  int bufferSize,
  FileOptions options
)

Parameters

File.Create(String, Int32, FileOptions) 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.

Returns

File.Create(String, Int32, FileOptions) method returns A new file with the specified buffer size.

Example


using System;/*w w w .  j  a  va2 s. c  o 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, 1024, FileOptions.RandomAccess))
        {
            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);
            }
        }
    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter