Summary of STREAMWRITER objects in ASP. NET

Source: Internet
Author: User

The streamreader object is used to read files, and the streamwriter object is used to write files. The attributes and methods of streamwriter and streamreader are similar.

1. Create a streamwriter object

To create a streamwriter object, you can use the createtext method of the file object or the constructor of the streamwriter object.
(1) Use the createtext method of the file object
Dim mikecatwriter as streamwriter
Dim mikecatfile as file
Mikecatwriter = mikecatfile. createtext ("c: \ mikecat.txt ")
(2) Use the constructor of the streamwriter object
Dim mikecatwriter as new streamwriter ("c: \ mikecat.txt") 2. Main method of streamwriter object

The streamwriter object writes data to a file. The following describes the specific operation methods.
(1) close Method
Like the streamreader object, the close method is also a required method for streamwriter objects. After the streamwriter object is used to complete the write operation, you must use the close method to release the files operated by the streamwriter object and other system resources. If the close method is not used, other processes cannot perform any operations on the file.
Sub close ()
(2) write Method
This method is used to write data to a file.
Sub write (string)
The string parameter can be a number, character, or string. Both characters and numbers are written into the file as strings.
Writeline Method
Corresponds to the readline method of the streamreader object. This method is used to write a row of data.
Sub writeline (string)
The string parameter can be a number, character, or string. Both characters and numbers are written into the file as strings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.