5.5.1 methods for creating TextStream objects
There are three common methods for creating or opening a text file and returning the Textstram object, as shown in table 5-13:
Table 5-13 methods and descriptions for creating TextStream objects
Method
Description
CreateTextFile
(Filename,overwrite,unicode)
Creates a new text file on disk with the specified filename filename, and returns a TextStream object corresponding to the file. If the optional overwrite parameter is set to True, a file of the same name with the same path will be overwritten. The default overwrite is false. If the optional Unicode parameter is set to False, the contents of the file are stored in Unicode format. The default Unicode is False
OpenTextFile
(Filename,iomode,create,format)
Open or create (if not present) a file named filename, and return the TextStream object corresponding to the file. The filename parameter can contain an absolute or relative path. The IOMode parameter describes the type of access required. Allowable values are ForReading (1) (default), ForWriting (2), ForAppending (8). When you write to or append to a file that does not exist, a new file is created if the Create argument is set to true. The default create is false. The format parameter describes the data formatting when you read or write a file. The allowable value is Tristatefalse (0) (default), the description is in ASCII data format, TristateTrue (-1) description is in Unicode data format, Tristateusedefault (-2) indicates that the data uses the system default format
OpenAsTextStream
(Iomode,format)
Opens a specified file and returns a TextStream object that can be used to read, write, or append to the file. The IOMode parameter illustrates the type of access that is required. Allowable values are ForReading (1) (default), ForWriting (2), ForAppending (8). The format parameter describes the data formats for reading and writing files. The allowable value is Tristatefalse (0) (default), the description is in ASCII data format, TristateTrue (-1) description is in Unicode data format, Tristateusedefault (-2) indicates using system default format
The methods listed above differ in the implementations in FileSystemObject, folder, and file objects. As shown in table 5-14:
Table 5-Methods contained in 143 objects
Method
FileSystemObject objects
Folder Object
File Object
CreateTextFile
Yes
Yes
Yes
OpenTextFile
Yes
No
No
OpenAsTextStream
No
No
Yes
Therefore, you can use these methods to create a new text file, or to open an existing file. You can get a TextStream object corresponding to the file, and you can manipulate the file using the properties and methods of the TextStream object.
1. Create a new text file
You can create a new text file by using the CreateTextFile method, or overwrite a file that already exists. The returned TextStream object can be used to read and write files.
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