Creating a Text File

Article Tools

System.IO.File class provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects.
The CreateText method creates or opens a file for writing UTF-8 encoded text.
The following example demonstrates some of the main members of the File class.

Dim pathStr
Dim sysIoFile, sw

pathStr = "c:\MyTest.txt"
Set sysIoFile = DotNetFactory.CreateInstance( "System.IO.File" )
If CBool( sysIoFile.Exists( pathStr ) ) = False Then
   ' ** Create a file to write to.
   Set sw = sysIoFile.CreateText( pathStr )
   sw.WriteLine("Hello")
   sw.WriteLine("And")
   sw.WriteLine("Welcome")
   sw.Flush()
   sw.Close()
End If
Set sw = Nothing : Set sysIoFile = Nothing

 

Previous postWrite to a Text File Next postGet File Information

Related Posts

Post Your Comment

You must be logged in to post a comment.