| xHarbour Reference Documentation > Class Reference (textmode) |
![]() |
![]() |
![]() |
Creates a new TStreamFileWriter object.
TStreamFileWriter():new( <cFileName>, ;
[<nFileAttr>] ) --> oTStreamFileWriter
Attributes for binary file creation
| Constant | Value | Attribute | Description |
|---|---|---|---|
| FC_NORMAL *) | 0 | Normal | Creates a normal read/write file |
| FC_READONLY | 1 | Read-only | Creates a read-only file |
| FC_HIDDEN | 2 | Hidden | Creates a hidden file |
| FC_SYSTEM | 4 | System | Creates a system file |
| *) default attribute | |||
The function returns a new TStreamFileWriter object and method :new() initializes the object.
TStreamFileWriter objects encapsulate low-level file functions for writing streams of data into a file. The class inherits from the abstract class TStream(), which maintains information about the stream size (file size) and current position within the stream data (file pointer).
when the file <cFileName> does not exist, it is created during object initialization. when it exists it is opened and the file pointer is positioned at the end-of-file, so that new data is appended to the existing file with method :write() or :writeByte(). To overwrite an existing file, position the file pointer at the beginning with method :seek().
| See also: | FileReader(), FileWriter(), TStream(), TStreamFileReader() |
| Category: | Object functions , xHarbour extensions |
| Header: | fileio.ch |
| Source: | rtl\stream.prg |
| LIB: | lib\xhb.lib |
| DLL: | dll\xhbdll.dll |
// The example lists all file names of the current directory
// to a text file.
PROCEDURE Main
LOCAL aFiles := Directory()
LOCAL cFile := "Directory.txt"
LOCAL oWriter:= TStreamFileWriter():new( cFile )
LOCAL aFile
FOR EACH aFile IN aFiles
oWriter:write( aFile[1],, Len(aFile[1]) )
oWriter:writeByte( Chr(13) )
oWriter:writeByte( Chr(10) )
NEXT
oWriter:close()
RETURN
http://www.xHarbour.com