| VB.NET | |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 |
' 一時フォルダ名を取得 Console.WriteLine("一時フォルダのパス: " + System.IO.Path.GetTempPath()) Dim tempFile As String = System.IO.Path.GetTempFileName() Console.WriteLine("作成された一時ファイル名: " + tempFile) ' 一時ファイルへの書き込み Dim writer As System.IO.StreamWriter = Nothing Try writer = New System.IO.StreamWriter(tempFile, False, System.Text.Encoding.GetEncoding(932)) writer.WriteLine("一時ファイルへの書き込みテスト。") writer.WriteLine("うまく書き込めたかな・・・。") Finally If Not writer Is Nothing Then writer.Close() End Try ' 一時ファイルからの読込 Dim reader As System.IO.StreamReader = Nothing Try reader = New System.IO.StreamReader(tempFile, System.Text.Encoding.GetEncoding(932)) Dim strLine As String = reader.ReadLine() While Not strLine Is Nothing Console.WriteLine(strLine) strLine = reader.ReadLine() End While Finally If Not reader Is Nothing Then reader.Close() End Try ' 使用した一時ファイルを削除 System.IO.File.Delete(tempFile) |
| 出力例 | |
一時フォルダのパス: (現在のユーザーの一時フォルダ) 作成された一時ファイル名: (現在のユーザーの一時フォルダ)\(一意な一時ファイル名) 一時ファイルへの書き込みテスト。 うまく書き込めたかな・・・。 Press any key to continue | |