In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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 achieve file operation, the article is very detailed, has a certain reference value, interested friends must read it!
VB.NET file operation opens and closes files
1. Sequential files
To open the sequential file, we can use the Openstatement. Its format is as follows:
Open pathname For [Input | Output | Append] As [#] filenumber [Len = buffersize]
Description:
1) the parameter pathname indicates the name of the file to be opened, which can contain the drive and directory
2) Input Output and Append are used to set how sequential files are opened. Where Input means to read data from an open file. When you open a file in this way, the file must exist, or an error will occur. Output means to write data to an open file. When you open a file in this way, the original data in the file is overwritten and the new data is written from the file. If the file does not exist, create a new file. Append means to add data to an open file. When opened in this way, the original data in the file will be retained and the new data will be added from the beginning of the file. If the file does not exist, create a new file.
3) the As [#] filenumber clause is used to specify the file number for the open file. When reading and writing to a file, use the file number to indicate the file. The file number is an integer between 1 and 511, which can be either a number or a variable. It can also be omitted.
4) when copying data between a file and a program, the Len=buffersize clause specifies the number of characters in the buffer.
For example:
Open App.Path + "/ test.dat" For Output As 1 Open App.Path + "/ test.dat" For Output As 1
These two lines of code create a text file called test.dat in the directory where the current application is located, and assign the file number as 1. 0.
Open App.Path + "/ test.dat" For Input As [#] filenumber
This statement reads data from a text file.
Open App.Path + "/ test.dat" For Append As [#] filenumber
This statement is like adding data to a text file.
2. Random files
Before you can manipulate a random file, you must first define the record type used to save the data item. The records are user-defined data types, and they are the basic structure for storing data in random files. For example:
Type Student No As Integer Name As String * 20 age As Integer End Type Dim Stud As Student 'defines a variable that can store student materials.
In random files, all the data will be saved to several records with Student type structure, and the data read from random files can be stored in the variable Stud.
Then we can open and read and write the file. The following is the syntax format for opening random files:
Open filename For Random as [#] filenumber Len = Reclength
Description:
1) parameters filename and filenumber denote file name or file number respectively.
2) the keyword Random indicates that the file is opened randomly
3) the Len clause is used to set the record length, which is specified by the parameter Reclength. The value of Reclength must be greater than 0 and must be consistent with the length of the defined record structure. The length of a record is calculated by adding the length of each element in the record structure. For example, the length of the previously declared Student should be 2 "20" 2 "24 bytes.
The way to open a random file with a record type of Student is:
Open "c:/Student.txt" For Random As # 1 Len = 25 is all the content of the article "how to manipulate 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.
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.