1. Write
FilesystemObject can translate files into file streams.
first step:
example:
Copy code code as follows:
Var FSO = New Activexobject (scripting.filesystemObject);
Create an object that can translate the file into a file stream.
Step 2: Used to create a TextStream object
There are three attributes in parentheses
1. The absolute path of the file
2. The constant of the file is only read = 1, only write = 2, and add = 8 and other permissions. (Forreading, Forwriting, or ForappEnding.);
3. A Boolean value allows a new construction to be True.
example:
Copy code code as follows:
Var f = fso.createtextFile ("C: /A.TXT", 2, TRUE);
Step 3: The method of calling TextStream
1. Write
2. Writeline (to add a new change symbol at the end)
3. WriteBlanklines (add one or more empty lines)
example:
Copy code code as follows:
f.writeline ("wo shi di yi haang");
Step 4:
Close the textstream object:
Example: f.close ();
2. Read
first step:
Copy code code as follows:
Var FSO = New Activexobject (scripting.filesystemObject);
Create an object that can translate the file into a file stream.
Step 2: Used to create a TextStream object
There are three attributes in parentheses
4. The absolute path of the file
5. The constant of the file is only read = 1, only write = 2, and add = 8 and other permissions. (Forreading, Forwriting, or ForappEnding.);
6. A Boolean value allows new construction to be true as FALSE;
example:
Copy code code as follows:
Var F = FSO.OPENTEXTFILE ("C: /A.TXT", 1, TRUE);
Step 3: Calling and reading method
1. Read (used to read the number specified in the file)
2. Readline (read a whole line, but does not include changes)
3. Readall (then read the entire content of the text file);
Determine whether to read the last line
Copy code code as follows:
While (! F.atendofstream)
{{
f.readline ();
}
Step 4:
Close the textstream object:
Example: f.close ();
Below is an example of an HTML opening TXT file.
Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" /> />
<Title> Hello </tictle>
</head>
<body>
<div ID = "AA"> </DIV>
<script language = "javascript">
var fso, ts, s;
var Forreading = 1;
fSO = New Activexobject ("Scripting.fileSystemObject");
ts = fso.opentextFile ("d: //testfile.txt", forreading);
s = ts.readline ();
document.GetelementByid ("aa"). Innerhtml = s;
</script>
</body>
</html>