FileOptions 列挙体とは? わかりやすく解説

FileOptions 列挙体

メモ : この列挙体は、.NET Framework version 2.0新しく追加されたものです。

FileStream オブジェクト作成するための追加オプション表します

この列挙体には、メンバ値のビットごとの組み合わせ可能にする FlagsAttribute 属性含まれています。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<FlagsAttribute> _
Public Enumeration FileOptions
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum FileOptions
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[FlagsAttribute] 
public enum class FileOptions
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute FlagsAttribute() */ 
public enum FileOptions
SerializableAttribute 
ComVisibleAttribute(true) 
FlagsAttribute 
public enum 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);
    }
}

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からFileOptions 列挙体を検索した結果を表示しています。
Weblioに収録されているすべての辞書からFileOptions 列挙体を検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFileOptions 列挙体 を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「FileOptions 列挙体」の関連用語

FileOptions 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FileOptions 列挙体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS