Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read and write text files by VB.NET

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces VB.NET how to read and write text files, the article is very detailed, has a certain reference value, interested friends must read it!

To save the text to a file, create a FileStream-based StreamReader object, and then call the Write method to write the text you want to save to the file.

The following VB.NET read and write text file code prompts the user with SaveFileDialog to specify a file to save the contents of the TextBox1.

SaveFileDialog1.Filter = _

"Text Files | * .txt | All Files | *. *"

SaveFileDialog1.FilterIndex = 0

If SaveFileDialog1.ShowDialog =

DialogResult.OK Then

Dim FS As FileStream =

SaveFileDialog1.OpenFile

Dim SW As New StreamWriter (FS)

SW.Write (TextBox1.Text)

SW.Close ()

FS.Close ()

End If

VB.NET can also read and write a text file, using a similar statement, we read a text file and display the contents in the TextBox control. The ReadToEnd method of StreamReader returns the entire contents of the file.

OpenFileDialog1.Filter = _

"Text Files | * .txt | All Files | *. *"

OpenFileDialog1.FilterIndex = 0

If OpenFileDialog1.ShowDialog

= DialogResult.OK Then

Dim FS As FileStream

FS = OpenFileDialog1.OpenFile

Dim SR As New StreamReader (FS)

TextBox1.Text = SR.ReadToEnd

SR.Close ()

FS.Close ()

End If

The above is all the contents of the article "how to read and write text files in VB.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report