Writing Text to a File (Visual Basic)

visual This example writes a string to a text file using the WriteLine method of the StreamWriter class.

Dim file As New System.IO.StreamWriter("c:\test.txt")
file.WriteLine("Here is the first line.")
Compiling the Code
This example requires:

A reference to System namespace.
Robust Programming
The following conditions may cause an exception:

The file exists and is read-only (IOException Class).
The disk is full (IOException Class).
The pathname is too long (PathTooLongException Class).
This example creates a new file, if the file does not already exist. If an application needs to create a file, that application needs Create access for the folder (see Access Control). If the file already exists, the application needs only Write access, a lesser privilege. Where possible, it is more secure to create the file during deployment, and only grant Read access to a single file, rather than Create access for a folder.


E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >



如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。