您的位置:首页 > 编程语言 > VB

【VB.net自学笔记(三)】StreamReader与StreamWriter的应用——UTF-8文本的读写

2017-12-12 09:54 525 查看
StreamReader,属于System.IO的子类。

Function SRead(path As String)	'输入文件的路径
Dim txt As System.IO.StreamReader
Dim st As String
st = ""
txt = New StreamReader(path)
st = txt.ReadToEnd
SRead = st
end function


StreamWriter,属于System.IO的子类。

Sub SWrite(txt As String, path As String, filename As String) '一次性输出文本
Using logObject As StreamWriter = New StreamWriter(path & "\" & filename )
logObject.Write(txt)
logObject.Close()
End Using
End Sub

Sub LWrite(txt As string, path As string, filename As String) '逐行输出
Dim nowtime
Using logObject As StreamWriter = File.AppendText(path & "\" & filename )
logObject.WriteLine(txt)
logObject.Close()
End Using
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: