如何在 VB.NET 中编写以下算法的代码?
Procedure logfile()
{
if "C:\textfile.txt"=exist then
open the textfile;
else
create the textfile;
end if
go to the end of the textfile;
write new line in the textfile;
save;
close;
}
Dim FILE_NAME As String = "C:\textfile.txt"
Dim i As Integer
Dim aryText(4) As String
aryText(0) = "Mary WriteLine"
aryText(1) = "Had"
aryText(2) = "Another"
aryText(3) = "Little"
aryText(4) = "One"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
For i = 0 To 4
objWriter.WriteLine(aryText(i))
Next
objWriter.Close()
MsgBox("Text Appended to the File")
如果将第二个参数设置为True
in the System.IO.StreamWriter
的构造函数,如果文件已存在,它将附加到文件,如果不存在,则创建一个新文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)