Use FileStream inside a using statement : Using Statement « File Directory Stream « C# / CSharp Tutorial






using System;
using System.IO;
using System.Text;

public class MainClass
{
    static void Main() {
        using( FileStream fs = File.Open( "log.txt", FileMode.Append, FileAccess.Write, FileShare.None ) ) {
            Byte[] msg = new UTF8Encoding(true).GetBytes("string \n");
            fs.Write( msg, 0, msg.Length );
        }
    }
}








15.33.Using Statement
15.33.1.Use object inside using statement
15.33.2.Create object inside the using statement
15.33.3.Using Statement: using DIRECTIVE, not using statement
15.33.4.Use FileStream inside a using statement
15.33.5.Dispose a StreamWriter by using 'using'
15.33.6.Using statement to deal with multiple resources
15.33.7.Nested using statement