我已阅读了如何在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
所以是的,这真的只是创建文件(那里没问题,文件是用正确的日期和位置制作的)但是当我打开文件时它是空的!有什么建议吗?
答案 0 :(得分:0)
尝试使用此代码
Dim file_ As System.IO.StreamWriter
file_ = My.Computer.FileSystem.OpenTextFileWriter(todayFile, True)
file_.WriteLine("sandwich")
file_.Close()