作成日:
テキストファイル出力
File.WriteAllText()でテキストファイルを出力できます。
string filepath = @"test.txt";
string data = "test data.";
File.WriteAllText(filepath, data, System.Text.Encoding.UTF8);
上記だとBOM付きのUTF-8で出力します。BOMをつけない場合はBOMなしのエンコーディングを指定します。
string filepath = @"test.txt";
string data = "test data.";
System.Text.UTF8Encoding utf8WithoutBom = new System.Text.UTF8Encoding(false);
File.WriteAllText(filepath, data, utf8WithoutBom);