通过 VB.NET 创建/编辑文本文件 [英] Creating/editing textfile through VB.NET
本文介绍了通过 VB.NET 创建/编辑文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 VB.NET 中编写下面的算法?
How do I code the algorithm below in 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")
如果在 System.IO.StreamWriter
的构造函数中将第二个参数设置为 True
,它将附加到一个文件(如果它已经存在),或者创建一个新的一个如果没有.
If you set the second parameter to True
in the System.IO.StreamWriter
's constructor it will append to a file if it already exists, or create a new one if it doesn't.
这篇关于通过 VB.NET 创建/编辑文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文