4
テキストファイルを作成してこのファイルにテキストを書きたいが、コードでテキストファイルを作成できない。テキストファイルを作成して書き込む
エラーメッセージ:
UnauthorizedAccessExcepion was unhandled by user code
Access to the path 'c:\save.txt' is denied.
私のコード:Windowsの、Cのルートのより新しいバージョンで
Dim fileLoc As String = "c:\save.txt"
Dim fs As FileStream = Nothing
If (Not File.Exists(fileLoc)) Then
fs = File.Create(fileLoc)
Using fs
End Using
End If
If File.Exists(fileLoc) Then
Using sw As StreamWriter = New StreamWriter(fileLoc)
a = "Test: " + TextBox1.Text
c = "=============================================="
sw.Write(a)
sw.Write(c)
End Using
End If
を! :]また、My Documentsファイルにtxtファイルを作成する方法は? –
'SaveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); ' – Isuru
Dim fileLoc As String = SaveFileDialog1.InitialDirectory +" \ save.txt "?? –