使用流写入器将行写入文件
Write Line to file with stream writer
我已经在 Preserving existing text when writing to file 阅读了如何使用 streamWriter
然而,即使我的代码几乎相同,但无论我做什么,都不会将任何内容写入文件。这是代码:
Private Sub Main()
Dim todaysdate As String = DateTime.Today
todaysdate = todaysdate.Replace("/", ".")
Dim todayFile As String = "dated\" & todaysdate & ".txt."
'this just creates the name and filepath that i want my file to be located at
If File.Exists(todayFile) = False Then
Dim Day As StreamWriter
Day = New StreamWriter(todayFile, True)
Day.WriteLine("sandwhich")
end if
end sub
所以是的,这实际上只是创建文件(没问题,文件是用正确的日期和位置创建的)但是当我打开文件时它是空的!有什么建议吗?
尝试使用此代码
Dim file_ As System.IO.StreamWriter
file_ = My.Computer.FileSystem.OpenTextFileWriter(todayFile, True)
file_.WriteLine("sandwich")
file_.Close()
我已经在 Preserving existing text when writing to file 阅读了如何使用 streamWriter 然而,即使我的代码几乎相同,但无论我做什么,都不会将任何内容写入文件。这是代码:
Private Sub Main()
Dim todaysdate As String = DateTime.Today
todaysdate = todaysdate.Replace("/", ".")
Dim todayFile As String = "dated\" & todaysdate & ".txt."
'this just creates the name and filepath that i want my file to be located at
If File.Exists(todayFile) = False Then
Dim Day As StreamWriter
Day = New StreamWriter(todayFile, True)
Day.WriteLine("sandwhich")
end if
end sub
所以是的,这实际上只是创建文件(没问题,文件是用正确的日期和位置创建的)但是当我打开文件时它是空的!有什么建议吗?
尝试使用此代码
Dim file_ As System.IO.StreamWriter
file_ = My.Computer.FileSystem.OpenTextFileWriter(todayFile, True)
file_.WriteLine("sandwich")
file_.Close()