1. Write
FileSystemObject can translate files into a file stream.
The first step:
Cases:
The code is as follows:
Var fso=New
Create an object that can translate the file into a file stream.
Step two: Use to create a TextStream object
There are three properties inside the parentheses
1. Absolute path to the file
2. The file's constant number is read Only = 1, write only = 2, append =8 and other permissions. (ForReading, ForWriting, or forappending. );
3. A Boolean value that allows new is true instead of false;
Cases:
The code is as follows:
Var f=fso.createtextfile ("C:\a.txt", 2,true
Step three: Call the TextStream method
1. Write (do not add new line breaks at the end of the write data)
2. WriteLine (to add a new newline character at the end)
3. WriteBlankLines (add one or more empty rows)
Cases:
The code is as follows:
Fourth Step:
To close the TextStream object:
Example: F.close ();
2. Read
The first step:
The code is as follows:
Var fso=New
Create an object that can translate the file into a file stream.
Step two: Use to create a TextStream object
There are three properties inside the parentheses
4. Absolute path to the file
5. The file's constant number is read Only = 1, write only = 2, append =8 and other permissions. (ForReading, ForWriting, or forappending. );
6. A Boolean value that allows new is true instead of false;
Cases:
The code is as follows:
Var f=fso.opentextfile ("C:\a.txt", 1,true
Step three: Call the Read method
1. Read (for reading a specified number of characters in a file)
2. ReadLine (reads a whole line, but does not include newline characters)
3. ReadAll (then reads the entire contents of the text file);
Determine if the last line is read
The code is as follows:
while (!
Fourth Step:
To close the TextStream object:
Example: F.close ();
Here is an example of an HTML open TXT file.
The code is as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> var FSO, TS, S;
var ForReading = 1 = new activexobject (" Scripting.FileSystemObject " = Fso. OpenTextFile ("D:\\testfile.txt" = ts. ReadLine (); document.getElementById ( "AA"). Innerhtml=s; </script> </body>
JavaScript write txt and read TXT file example