xHarbour Reference Documentation > Class Reference (textmode) |
Creates a new TStreamFileReader object.
TStreamFileReader():new( <cFileName>, ; [<nOpenMode>] ) --> oTStreamFileReader
File open modes
Constant | Value | Description |
---|---|---|
FO_READ | 0 | Open file for reading |
FO_WRITE | 1 | Open file for writing |
FO_READWRITE *) | 2 | Open file for reading and writing |
*) default |
Constants that define the access or file sharing rights can be added to an FO_* constant. They specify how file access is granted to other applications in a network environment.
File sharing modes
Constant | Value | Description |
---|---|---|
FO_COMPAT *) | 0 | Compatibility mode |
FO_EXCLUSIVE | 16 | Exclusive use |
FO_DENYWRITE | 32 | Prevent other applications from writing |
FO_DENYREAD | 48 | Prevent other applications from reading |
FO_DENYNONE | 64 | Allow others to read or write |
FO_SHARED | 64 | Same as FO_DENYNONE |
*) default |
The function returns a new TStreamFileReader object and method :new() initializes the object.
TStreamFileReader objects encapsulate low-level file functions for reading a file as a stream of data. 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).
See also: | FileReader(), FileWriter(), TStream(), TStreamFileWriter() |
Category: | Object functions , xHarbour extensions |
Header: | fileio.ch |
Source: | rtl\stream.prg |
LIB: | lib\xhb.lib |
DLL: | dll\xhbdll.dll |
// The example reads an entire file in blocks of 4096 bytes and fills // them into an array #define BLOCK_SIZE 4096 PROCEDURE Main LOCAL oReader, cFile, cBuffer, nBytes, aBlocks aBlocks := {} cBuffer := SPace( BLOCK_SIZE ) cFile := "myfile.log" oReader := TStreamFileReader():new( cFile ) IF oReader:handle < 0 ? "Error opening file:", FError() QUIT ENDIF DO WHILE .T. nBytes := oReader:read( @cBuffer, , BLOCK_SIZE ) IF nBytes == BLOCK_SIZE AAdd( aBlocks, cBuffer ) ELSE // end of file reached AAdd( aBlocks, SubStr( cBuffer, nBytes ) ) EXIT ENDIF ENDDO oReader:close() ? Len( aBlocks ), "Blocks of", BLOCK_SIZE, "bytes read" RETURN
http://www.xHarbour.com