Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.
object.OpenAsTextStream([iomode, [format]])
The iomode argument can have any of the following settings:
Constant | Value | Description |
---|---|---|
ForReading | 1 | Open a file for reading only. You can't write to this file. |
ForWriting | 2 | Open a file for writing. If a file with the same name exists, its previous contents are overwritten. |
ForAppending | 8 | Open a file and write to the end of the file. |
The format argument can have any of the following settings:
Constant | Value | Description |
---|---|---|
TristateUseDefault | -2 | Opens the file using the system default. |
TristateTrue | -1 | Opens the file as Unicode. |
TristateFalse | 0 | Opens the file as ASCII. |
The OpenAsTextStream method provides the same functionality as the OpenTextFile method of the FileSystemObject. In addition, the OpenAsTextStream method can be used to write to a file.
The following code illustrates the use of the OpenAsTextStream method:
[JScript] function TextStreamTest( ) { var fso, f, ts, s; var ForReading = 1, ForWriting = 2, ForAppending = 8; var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0; fso = new ActiveXObject("Scripting.FileSystemObject"); fso.CreateTextFile( "test1.txt" ); // Create a file. f = fso.GetFile("test1.txt"); ts =f.OpenAsTextStream(
ForWriting,
TristateUseDefault)
; ts.Write( "Hello World" ); ts.Close( ); ts =f.OpenAsTextStream(
ForReading,
TristateUseDefault)
; s = ts.ReadLine( ); ts.Close( ); return(s); } [VBScript] Function TextStreamTest Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Dim fso, f, ts Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateTextFile "test1.txt" ' Create a file. Set f = fso.GetFile("test1.txt") Set ts =f.OpenAsTextStream(
ForWriting,
TristateUseDefault)
ts.Write "Hello World" ts.Close Set ts =f.OpenAsTextStream(
ForReading,
TristateUseDefault)
TextStreamTest = ts.ReadLine ts.Close End Function
file: /Techref/language/asp/VBS/VBSCRIPT/jsmthopenastextstream.htm, 4KB, , updated: 2005/8/9 12:38, local time: 2024/11/24 19:01,
18.224.54.61:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/language/asp/VBS/VBSCRIPT/jsmthopenastextstream.htm"> OpenAsTextStream Method (Scripting)</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.