Objet ASP TextStream


L'objet TextStream est utilisé pour accéder au contenu d'un fichier texte.


Plus d'exemples


un fichier texte Comment lire un fichier texte.


Comment lire seulement une partie d'un fichier TextStream.


Comment lire une ligne d'un fichier TextStream.


Comment lire toutes les lignes d'un fichier TextStream.


Comment ignorer un nombre spécifié de caractères lors de la lecture du fichier TextStream.


Comment sauter une ligne lors de la lecture du fichier TextStream.


Comment renvoyer le numéro de ligne actuel dans un fichier TextStream.


de colonne Comment obtenir le numéro de colonne du caractère courant dans un fichier.


L'objet TextStream

L'objet TextStream est utilisé pour accéder au contenu des fichiers texte.

Le code suivant crée un fichier texte (c:\test.txt) puis écrit du texte dans le fichier (la variable f est une instance de l'objet TextStream) :

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile("c:\test.txt",true)
f.WriteLine("Hello World!")
f.Close
set f=nothing
set fs=nothing
%>


Pour créer une instance de l'objet TextStream, vous pouvez utiliser les méthodes CreateTextFile ou OpenTextFile de l'objet FileSystemObject, ou vous pouvez utiliser la méthode OpenAsTextStream de l'objet File.

Les propriétés et les méthodes de l'objet TextStream sont décrites ci-dessous :

Propriétés

Property Description
AtEndOfLine Returns true if the file pointer is positioned immediately before the end-of-line marker in a TextStream file, and false if not
AtEndOfStream Returns true if the file pointer is at the end of a TextStream file, and false if not
Column Returns the column number of the current character position in an input stream
Line Returns the current line number in a TextStream file

Méthodes

Method Description
Close Closes an open TextStream file
Read Reads a specified number of characters from a TextStream file and returns the result
ReadAll Reads an entire TextStream file and returns the result
ReadLine Reads one line from a TextStream file and returns the result
Skip Skips a specified number of characters when reading a TextStream file
SkipLine Skips the next line when reading a TextStream file
Write Writes a specified text to a TextStream file
WriteLine Writes a specified text and a new-line character to a TextStream file
WriteBlankLines Writes a specified number of new-line character to a TextStream file