Savetextfile-save or append text to a file

Source: Internet
Author: User

I can see a method for storing or adding text to a file on the Internet. It feels good to share with you! Pai_^



Original article @ devx.com



'Saves a text file. If the destination file already exists,

'Its content can be replaced, or the new content can be appended

'At the end of the file, according to the last parameter

 

'Note: the destination directory must exist, otherwise the file is not

'Saved and the function returns false

'Usage: dim result as Boolean = savetextfile ("D: \ test.txt", filecontent)

 

Function Savetextfile(Byval Filepath As String,Byval Filecontent As String,_

Optional Byval Append As Boolean=False)As Boolean

 

Dim SW As System.Io.Streamwriter

Try

SW=New System.Io.Streamwriter(Filepath,Append)

SW.Write(Filecontent)

Return True

Catch E As Exception

Return False

Finally

If Not SW Is Nothing Then SW.Close()

End Try

End Function


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.