xHarbour Reference Documentation > Class Reference (textmode) xHarbour Developers Network  

TStreamFileWriter()

Creates a new TStreamFileWriter object.

Syntax

TStreamFileWriter():new( <cFileName>, ;
                        [<nFileAttr>] ) --> oTStreamFileWriter

Arguments

<cFilename>
This is a character string holding the name of the file to create and/or write to. It must include path and file extension. If the path is omitted from <cFileName>, the file is created or opened in the current directory.
<nFileAttr>
A numeric value specifying one or more attributes associated with the file to create or open. #define constants from the FILEIO.CH file can be used for <nFileAttr> as listed in the table below:

Attributes for binary file creation
ConstantValueAttributeDescription
FC_NORMAL *)0NormalCreates a normal read/write file
FC_READONLY1Read-onlyCreates a read-only file
FC_HIDDEN2HiddenCreates a hidden file
FC_SYSTEM4SystemCreates a system file

Return

The function returns a new TStreamFileWriter object and method :new() initializes the object.

Description

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().

Instance variables

:cFile
Name of the file being written.
:handle
Numeric low-level file handle.

Methods

:close() --> self
Closes the data stream, or file.
:finalize() --> self
Destructor method.
:seek( <nBytes>, <nOrigin> ) --> nPosition
Changes the position of the file pointer.
:write( <cBuffer>, [<nOffset>], [<nBytes>] ) --> nBytesWritten
Writes data from memory into the stream.
:writeByte( <cByte> ) --> self
Writes a single byte into the data stream.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe