1. Write
FileSystemObject to translate the file into a file stream.
Step one:
Example:
Var fso=new ActiveXObject(Scripting.FileSystemObject);
Creates an object that can translate a file into a file stream.
Step 2: Used to create a textStream object
There are three attributes in the brackets
1. The absolute path of the file
2. The constant of the file Read only=1, write only=2, append=8 and other permissions. (ForReading, ForWriting or ForAppending.);
3. A Boolean value is true if new creation is allowed, otherwise false;
Example:
Var f=fso.createtextfile(“C:a.txt”,2,true);
Step 3: Call the textStream method
1. Write (without adding a new line break at the end of the written data)
2. WriteLine (to add a new line break at the end) )
3. WriteBlankLines (add one or more blank lines)
Example:
f.writeLine(“wo shi di yi hang”);
Step 4:
Close the textStream object :
Example: f.close();
2. Reading
Step 1:
Var fso=new ActiveXObject(Scripting.FileSystemObject);
Create a file that can be translated into File stream object.
Step 2: Used to create a textStream object
There are three attributes in the brackets
4. The absolute path of the file
5. The constants of the file Read only=1, write only=2, append=8 and other permissions. (ForReading, ForWriting or ForAppending.);
6. A Boolean value is true if new creation is allowed, otherwise false;
Example:
Var f=fso.opentextfile(“C:a.txt”,1,true);
Step 3: Call the read method
1. Read (used to read the specified number of characters in the file)
2. ReadLine (read a whole line, but Excluding line breaks)
3. ReadAll (read the entire content of the text file);
Determine whether the last line has been read
while (!f.AtEndOfStream)
{
f.Readline();
}
Step 4:
Close textStream object:
Example: f.close();
The following is an html to open a txt file Example.