FileOptions 列挙体
この列挙体には、メンバ値のビットごとの組み合わせを可能にする FlagsAttribute 属性が含まれています。
名前空間: System.IOアセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <FlagsAttribute> _ Public Enumeration FileOptions

メンバ名 | 説明 | |
---|---|---|
Asynchronous | ファイルを非同期の読み取り用および書き込み用に使用できることを示します。 | |
DeleteOnClose | ファイルは使用しなくなった時点で自動的に削除されることを示します。 | |
Encrypted | ファイルは暗号化され、暗号化に使用したのと同じユーザー アカウントを使用する場合のみ復号化できることを示します。 | |
None | 追加のパラメータがないことを示します。 | |
RandomAccess | ファイルがランダムにアクセスされることを示します。システムは、これをファイル キャッシングを最適化するためのヒントとして使用できます。 | |
SequentialScan | ファイルは先頭から末尾まで順次アクセスされることを示します。システムは、これをファイル キャッシングを最適化するためのヒントとして使用できます。アプリケーションがランダム アクセスのファイル ポインタを移動させると、最適なキャッシングが行われない場合があります。ただし、操作は引き続き正常に実行されます。 このフラグを指定すると、大きなファイルを順次アクセスで読み取るアプリケーションのパフォーマンスを向上させることができます。通常は大きなファイルを順次に読み取るが、小さなバイト範囲をスキップする場合もあるアプリケーションについては、さらに顕著にパフォーマンスが向上します。 | |
WriteThrough | システムが中間キャッシュを使用して書き込みを行い、直接ディスクに移動することを示します。 |


FileStream オブジェクトを使用して、データをファイルに書き込んでからそのデータを読み取るコード例を次に示します。
Imports System Imports System.IO Imports System.Text Imports System.Security.AccessControl Module FileStreamExample Sub Main() Try ' Create a file and write data to it. ' Create an array of bytes. Dim messageByte As Byte() = Encoding.ASCII.GetBytes("Here is some data.") ' Specify an access control list (ACL) Dim fs As New FileSecurity() fs.AddAccessRule(New FileSystemAccessRule("DOMAINNAME\AccountName", FileSystemRights.ReadData, AccessControlType.Allow)) ' Create a file using the FileStream class. Dim fWrite As New FileStream("test.txt", FileMode.Create, FileSystemRights.Modify, FileShare.None, 8, FileOptions.None, fs) ' Write the number of bytes to the file. fWrite.WriteByte(System.Convert.ToByte(messageByte.Length)) ' Write the bytes to the file. fWrite.Write(messageByte, 0, messageByte.Length) ' Close the stream. fWrite.Close() ' Open a file and read the number of bytes. Dim fRead As New FileStream("test.txt", FileMode.Open) ' The first byte is the string length. Dim length As Integer = Fix(fRead.ReadByte()) ' Create a new byte array for the data. Dim readBytes(length) As Byte ' Read the data from the file. fRead.Read(readBytes, 0, readBytes.Length) ' Close the stream. fRead.Close() ' Display the data. Console.WriteLine(Encoding.ASCII.GetString(readBytes)) Console.WriteLine("Done writing and reading data.") Catch e As Exception Console.WriteLine(e) End Try Console.ReadLine() End Sub End Module
using System; using System.IO; using System.Text; using System.Security.AccessControl; namespace FileSystemExample { class FileStreamExample { public static void Main() { try { // Create a file and write data to it. // Create an array of bytes. byte[] messageByte = Encoding.ASCII.GetBytes("Here is some data."); // Specify an access control list (ACL) FileSecurity fs = new FileSecurity(); fs.AddAccessRule(new FileSystemAccessRule(@"DOMAINNAME\AccountName" , FileSystemRights.ReadData , AccessControlType.Allow)); // Create a file using the FileStream class. FileStream fWrite = new FileStream("test.txt", FileMode.Create, FileSystemRights.Modify, FileShare.None, 8, FileOptions.None, fs); // Write the number of bytes to the file. fWrite.WriteByte((byte)messageByte.Length); // Write the bytes to the file. fWrite.Write(messageByte, 0, messageByte.Length); // Close the stream. fWrite.Close(); // Open a file and read the number of bytes. FileStream fRead = new FileStream("test.txt", FileMode.Open); // The first byte is the string length. int length = (int)fRead.ReadByte(); // Create a new byte array for the data. byte[] readBytes = new byte[length]; // Read the data from the file. fRead.Read(readBytes, 0, readBytes.Length); // Close the stream. fRead.Close(); // Display the data. Console.WriteLine(Encoding.ASCII.GetString(readBytes)); Console.WriteLine("Done writing and reading data."); } catch (Exception e) { Console.WriteLine(e); } Console.ReadLine(); } } }
using namespace System; using namespace System::IO; using namespace System::Text; using namespace System::Security::AccessControl; using namespace System::Security::Principal; int main() { try { // Create a file and write data to it. // Create an array of bytes. array<Byte>^ messageByte = Encoding::ASCII->GetBytes("Here is some data."); // Specify an access control list (ACL) FileSecurity^ fs = gcnew FileSecurity(); fs->AddAccessRule( gcnew FileSystemAccessRule("MYDOMAIN\\MyAccount", FileSystemRights::Modify, AccessControlType::Allow)); // Create a file using the FileStream class. FileStream^ fWrite = gcnew FileStream("test.txt", FileMode::Create, FileSystemRights::Modify, FileShare::None, 8, FileOptions::None, fs); // Write the number of bytes to the file. fWrite->WriteByte((Byte)messageByte->Length); // Write the bytes to the file. fWrite->Write(messageByte, 0, messageByte->Length); // Close the stream. fWrite->Close(); // Open a file and read the number of bytes. FileStream^ fRead = gcnew FileStream("test.txt", FileMode::Open); // The first byte is the string length. int length = (int)fRead->ReadByte(); // Create a new byte array for the data. array<Byte>^ readBytes = gcnew array<Byte>(length); // Read the data from the file. fRead->Read(readBytes, 0, readBytes->Length); // Close the stream. fRead->Close(); // Display the data. Console::WriteLine(Encoding::ASCII->GetString(readBytes)); Console::WriteLine("Done writing and reading data."); } catch (IdentityNotMappedException^) { Console::WriteLine("You need to use your own credentials " + " 'MYDOMAIN\\MyAccount'."); } catch (IOException^ ex) { Console::WriteLine(ex->Message); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFileOptions 列挙体を検索する場合は、下記のリンクをクリックしてください。

- FileOptions 列挙体のページへのリンク