【 解 説 】
テキストをファイルに書き込むには、StreamWriterを使用します。
あとは、単純にWrite()メソッドで書き込みたいテキストを書き出していくだけです。
Stream類は閉じるのを忘れないようにしましょう。他のプロセスがそのファイルにアクセスできなくなります。
【 例 文 】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
StreamWriter writer = null; try { writer = new StreamWriter("this.txt", false, System.Text.Encoding.GetEncoding("shift-jis")); writer.Write("Text in the file!"); writer.Flush(); } finally { if(writer != null) { writer.Close(); } } |
■お薦め参考関連資料
Microsoft、Visual Studio、Visual Basic、Visual C#、Windows Vista、Windows Server、SQL Server、Visual C++、Visual Web Developerは、米国 Microsoft Corporationの米国及びその他の国における登録商標または商標です。