vb.net中,读取和写入文件

点击一个按钮,能实现读取和写入功能(读取(写入)txt文档),请高手给我详细代码!

写入:Dim sr As New IO.StreamWriter(Application.StartupPath & "/写入的文本.txt")
sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath & "/msg.txt")) Then
Dim fm As New IO.FileStream(Application.StartupPath & "/读取的文本.txt", FileMode.Open)
Dim sr As IO.StreamReader = New IO.StreamReader(fm)
Do While sr.Peek() >= 0
TextBox1.Text = sr.ReadLine() (读取文本到文本框)
Loop end if
温馨提示:答案为网友推荐,仅供参考
相似回答