ASP OpenAsTextStream Method
Last Updated :
22 Mar, 2021
The ASP OpenAsTextStream Method is used to return a TextStream object by opening a specified file. It can be used to perform certain operations on the file.
Syntax:
FileObject.OpenAsTextStream(mode, format)
Parameters: This method has two parameters as mentioned above and described below:
- mode: It specifies the mode that a file is opened in. It contains 3 constant values to perform operations on the file.
- ForReading (1): This opens the file for reading. The file cannot be written in this mode.
- ForWriting (2): This opens the file for writing.
- ForAppending (8): This opens the file for appending content to the end.
- format: Optional attribute. It contains three constant values which used to define a format of a file.
- TristateFalse (0): This opens the file as ASCII. This is the default format.
- TristateTrue (1): This opens the file as Unicode.
- TristateUseDefault (2): This opens the file using the system default.
Example: The below code demonstrates the ASP File.OpenAsTextStream Method.
ASP
<%
dim fs,f,ts
set fs=Server.CreateObject( "Scripting.FileSystemObject" )
'Getting the file to be read
Set f=fs.GetFile( "d:\GFG.txt" )
'Opening the file as a text stream
'in writing mode (2)
Set ts=f.OpenAsTextStream(2)
'Writing some content to the file'
ts.Write( "This is a GeeksforGeeks example" )
'Closing the stream
ts.Close
'Opening the file as a text stream
'in reading mode (1)
Set ts=f.OpenAsTextStream(1)
'Reading the contents of the file
Response.Write(ts.ReadAll)
'Closing the stream
ts.Close
set ts=nothing
set f=nothing
set fs=nothing
%>
|
Output:
This is a GeeksforGeeks example
Share your thoughts in the comments
Please Login to comment...