Xbasic
FILE.READB Function
Syntax
Data as B = file_pointer.ReadB(N Length)
Arguments
- LengthNumeric
The number of bytes of data to read.
Returns
- DataBinary
Returns the data from the file.
Description
Read bytes from file into a blob.
Discussion
The .READB() method retrieves a specified Number_of_Bytes from a file starting at the current file offset. The file is specified by the file object pointer. The .READB() method returns a blob. This is useful for reading binary files.
Example
The following example reads a Windows Bitmap (.BMP) file into a binary variable.
dim img as B dim fptr as P dim length as fptr = FILE.open("C:\ARTHUR.BMP", FILE_RO_SHARED) length = fptr.bytes_get() img = fptr.readb(length)
This example reads a JPEG image and writes it out as a Windows Bitmap (.BMP) image.
dim img as B dim img as B dim img2 as B dim fptr as P dim length as N fptr = FILE.open("C:\arthur.jpg", FILE_RO_SHARED) length = fptr.bytes_get() img = fptr.readb(length) img2 = jpeg_to_bitmap(img) fptr2 = file.create("c:\arthur2.bmp", FILE_RW_EXCLUSIVE) fptr2.writeb(img2) fptr2.close() fptr.close()
See Also