In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "VB.NET how to achieve text file operation", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VB.NET how to achieve text file operation" this article.
Open: as the name implies, its function is to open a file, in other words, to open a file is to gain some control. Generally speaking, when a file is open, only the opener can operate on it. When you open a file, specify an integer as the file number, and later operations are done for this code, not for the file name. A file number is also called a handle. In a program, a file number can only point to one file, and two files cannot have the same handle at the same time.
Close: closes the file, which releases control of the file.
Line Input: gets the contents of a file in a behavior unit, which refers to the content from the current location to the next newline character. The newline character is composed of two bytes Chr (13) & Chr (10). The constant vbCrLf has been defined in VB and can be used directly. It is important to note that when Line Input reads a line, the newline character at the end of the line is removed, so we should remember to fill in the newline character when reading each line to keep the content consistent with the file.
FreeFile: get the free file number, and use this function to get the file number to avoid file number conflicts.
VB.NET text file operations such as:
All the contents of the text file read by the Dim strFileName As String 'file name Dim lngHandle As Long' file handle Dim strAll As String 'store the contents of each line in the loop strFileName = "c:\ .txt"' get the handle of the file lngHandle = FreeFile () 'the parameter after For indicates how to open the file, Input is read, Output is overwrite write Append is appended to write Open strFileName For Input As lngHandle 'loop until the end of the file Do While Not EOF (lngHandle)' every read line is stored in the strLine variable Line Input # lngHandle, strLine 'connects what you read to the strAll variable, because Line Input removes the newline character, so here add all the contents shown by strAllstrAll = strAll & strLine & vbCrLf Loop' MsgBox strAll, vbInformation
Writing to VB.NET text files is relatively simple, with three steps: opening the file, writing text, and closing the file.
Code example:
Dim strFileName As String 'filename Dim lngHandle As Long' handle Dim strWrite As String 'text content to be written strFileName = "c:\ w.txt" lngHandle = FreeFile ()' get handle 'content to be written strWrite = "Sunset Lou Tou, Guan Hongsheng Li, Jiangnan Youzi. Read Wu Gou, shot all over the column, no one will, landing." Open strFileName For Output As lngHandle 'opens the file Print # lngHandle, and strWrite' writes the text Close lngHandle 'turns off the file MsgBox "write complete." The above vbInformation is all the contents of the article "how to manipulate text files with VB.NET". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.