我正在尝试检查文件是否存在,如果存在则什么都不做。如果文件不存在,则创建文本文件。然后我想将文本写入该文件。这段代码我哪里出错了?我只是想在文本文件中写入多行,而那部分不起作用。它正在创建文本文件......只是不写入它。
Dim file As System.IO.FileStream
Try
' Indicate whether the text file exists
If My.Computer.FileSystem.FileExists("c:\directory\textfile.txt") Then
Return
End If
' Try to create the text file with all the info in it
file = System.IO.File.Create("c:\directory\textfile.txt")
Dim addInfo As New System.IO.StreamWriter("c:\directory\textfile.txt")
addInfo.WriteLine("first line of text")
addInfo.WriteLine("") ' blank line of text
addInfo.WriteLine("3rd line of some text")
addInfo.WriteLine("4th line of some text")
addInfo.WriteLine("5th line of some text")
addInfo.close()
End Try