Create ,Read and write a text file

In this post, we are going to learn how to Create ,Read and write a text file .

Creating a text File:

Create a text File
‘Syntax : object.CreateTextFile(filename[, overwrite[, unicode]])
filename Required. Provide the full path of the file with the file name which you want to create.
overwrite Optional (If true, it will overwrite the file and if false, file will not be overwritten.If omitted, existing files are not overwritten.

Write into a text File:

Please read the comments above the code to understand what code is actually doing.


Read a text file:


Difference between AtEndOfStream and AtEndOfLine:

AtEndOfStream Returns true if the file pointer is at the end of a TextStream file; false if it is not
AtEndOfLine Returns true if the file pointer is at the end of a line in a file; false if it is not

Can we read all content at a time,if not line by line?
Yes,We can do this by using the method ReadAll.
oFile.ReadAll

Can we read character by character?
Yes,We can do this by using the method Read.
oFile.Read(no of character to read)

Print Friendly, PDF & Email
Send mail from outlook with an attachment
Use of FileSystemObject
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *