VB.NET
Dim sw As New System.IO.StreamWriter("C:\nobom\1.txt")
sw.Write("BOM情報無しで書き込み処理")
sw.Close()
C#System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\nobom\1.txt");
sw.Write("BOM情報無しで書き込み処理");
sw.Close();
UTF8EncodingでBOMを付加しないでファイルを書き込む方法VB.NET
Dim enc As System.Text.Encoding = New System.Text.UTF8Encoding(False)
Dim sw As New System.IO.StreamWriter("C:\nobom\1.txt", False, enc)
sw.Write("BOM無し")
sw.Close()
C#System.Text.Encoding enc = new System.Text.UTF8Encoding(false);
System.IO.StreamWriter sw = new System.IO.StreamWriter(
@"C:\nobom\1.txt", false, enc);
sw.Write("BOM無し");
sw.Close();
BOMが付くかつかないかを判定する方法VB.NET
Console.WriteLine(System.Text.Encoding.UTF8.GetPreamble().Length)
Dim enc As System.Text.Encoding = New System.Text.UTF8Encoding(False)
Console.WriteLine(enc.GetPreamble().Length)
C#Console.WriteLine(System.Text.Encoding.UTF8.GetPreamble().Length);
System.Text.Encoding enc = new System.Text.UTF8Encoding(false);
Console.WriteLine(enc.GetPreamble().Length);