[Javascript] view plaincopyprint? <Script language = "javascript" type = "text/javascript">
/*
Object. OpenTextFile (filename [, iomode [, create [, format])
Parameters
Object
Required. The object should be the name of FileSystemObject.
Filename
Required. Specifies the string expression of the file to be opened.
Iomode
Optional. It can be one of the three constants: ForReading, ForWriting, or ForAppending.
Create
Optional. Boolean value, indicating whether to create a new file when the specified filename does not exist. If a new file is created, the value is True. If the file is not created, the value is False. If not, no new file is created.
Format
Optional. Use one of the three-state values to specify the file opening format. If ignored, the file is opened in ASCII format.
Set
The iomode parameter can be any of the following settings:
Constant Value description
ForReading 1 open the file in read-only mode. This file cannot be written.
ForWriting 2 open the file in write mode
ForAppending 8 open the file and write it from the end of the file.
The format parameter can be any of the following settings:
Value description
TristateTrue open a file in Unicode format.
TristateFalse open an object in ASCII format.
TristateUseDefault: open a file by default.
*/
// Read the file
Function readFile (filename ){
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
Var f = fso. OpenTextFile (filename, 1 );
Var s = "";
While (! F. AtEndOfStream)
S + = f. ReadLine () + "\ n ";
F. Close ();
Return s;
}
// Write an object
Function writeFile (filename, filecontent ){
Var fso, f, s;
Fso = new ActiveXObject ("Scripting. FileSystemObject ");
F = fso. OpenTextFile (filename, 8, true );
F. WriteLine (filecontent );
F. Close ();
Alert ('OK ');
}
</Script>
<Html>
<Input type = "text" id = "in" name = "in"/>
<Input type = "button" value = "Write! "Onclick =" writeFile ('C:/Documents and Settings/Administrator/desktop/12.doc ', document. getElementById ('in '). value); "/> <br>
<Input type = "button" value = "Read! "Onclick =" document. getElementById ('show'). value = readFile ('f:/Appserv/www/12.txt '); "/> <br>
<Textarea id = "show" name = "show" cols = "100" rows = "20">
</Textarea>
</Html>
<Script language = "javascript" type = "text/javascript">
/*
Object. OpenTextFile (filename [, iomode [, create [, format])
Parameters
Object
Required. The object should be the name of FileSystemObject.
Filename
Required. Specifies the string expression of the file to be opened.
Iomode
Optional. It can be one of the three constants: ForReading, ForWriting, or ForAppending.
Create
Optional. Boolean value, indicating whether to create a new file when the specified filename does not exist. If a new file is created, the value is True. If the file is not created, the value is False. If not, no new file is created.
Format
Optional. Use one of the three-state values to specify the file opening format. If ignored, the file is opened in ASCII format.
Set
The iomode parameter can be any of the following settings:
Constant Value description
ForReading 1 open the file in read-only mode. This file cannot be written.
ForWriting 2 open the file in write mode
ForAppending 8 open the file and write it from the end of the file.
The format parameter can be any of the following settings:
Value description
TristateTrue open a file in Unicode format.
TristateFalse open an object in ASCII format.
TristateUseDefault: open a file by default.
*/
// Read the file
Function readFile (filename ){
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
Var f = fso. OpenTextFile (filename, 1 );
Var s = "";
While (! F. AtEndOfStream)
S + = f. ReadLine () + "\ n ";
F. Close ();
Return s;
}
// Write an object
Function writeFile (filename, filecontent ){
Var fso, f, s;
Fso = new ActiveXObject ("Scripting. FileSystemObject ");
F = fso. OpenTextFile (filename, 8, true );
F. WriteLine (filecontent );
F. Close ();
Alert ('OK ');
}
</Script>
<Html> www.2cto.com
<Input type = "text" id = "in" name = "in"/>
<Input type = "button" value = "Write! "Onclick =" writeFile ('C:/Documents and Settings/Administrator/desktop/12.doc ', document. getElementById ('in '). value); "/> <br>
<Input type = "button" value = "Read! "Onclick =" document. getElementById ('show'). value = readFile ('f:/Appserv/www/12.txt '); "/> <br>
<Textarea id = "show" name = "show" cols = "100" rows = "20">
</Textarea>
</Html>