vb.net (File object)

Source: Internet
Author: User

The file object represents a file, and there are some very useful ways to verify the existence of a file and rename and delete a file. For example:
Dim FL as File
Fl=new File ("Foo.txt")
if (fl. Exists) ' If the file Exists
Fl. Delete ' Delete it
End If
The user can also use the file object to get a FileStream object and then read and write the file data by using the FileStream object:
Dim TS as TextStream
Dim FS as FileStream
TS=FL. OpenText ' Open a text file for reading
FS=FL. OpenRead ' Open any file for reading
(1) Read a text file (textfile)
To read a text file, the user can use the file object to get a StreamReader object and then use the text stream's Read method:
Dim TS as StreamReader
TS=FL. OpenText ()
S=ts.readline
(2) Write a text document (write a-text file)
To create and write a text file, the user can get a Streamwrite object using the CreateText method, and then do the action, such as:
Dim SW as StreamWriter
SW=FL. CreateText
Sw.writeline ("Write text into file")
If a user wants to operate on a file that already exists, you can use an object with logical parameters to do so:
Sw=new StreamWriter (Path,true)

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.