Code: Writing Text to a File (Visual Basic)

王朝vb·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

ExampleDim file As New System.IO.StreamWriter("c:\test.txt")

file.WriteLine("Here is the first line.")

file.Close()

Compiling the CodeThis example requires:

A reference to System namespace. Robust ProgrammingThe 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). SecurityThis 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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航