ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / External file functions
  • Handling errors
  • Position in the file
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Reads a block of bytes in an external file.
AndroidAndroid Widget Java In this version, you can only read a character string from an external file in ANSI format.
Example
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)Ajax
// Open an external file
MyTextFile is DiskFile
ResRead is int
IF MyTextFile.Open("C:\MyDirectories\File.txt", foReadWrite) = True THEN
// Read operation in this file
ResRead = MyTextFile.Read(200)
...
END
Syntax

Reading a block of bytes in an external file Hide the details

<Result> = <File used>.Read(<Number of bytes to read>)
<Result>: Character string
  • Block of bytes that was read.
  • Empty string ("") if an error occurred. To get more details on the error, use ErrorInfo with the errMessage constant.
<File used>: DiskFile variable
Name of the DiskFile variable initialized with .Open or Create.
<Number of bytes to read>: Integer
Number of bytes to read (up to 2 147 483 648 bytes).
If the data is a Unicode string, the number of bytes to read corresponds to:
  • in UTF16: the number of characters multiplied by 2.
  • in UTF32: the number of characters multiplied by 4.
WINDEVWEBDEV - Server codeReports and QueriesiPhone/iPadIOS WidgetMac CatalystUser code (UMC)Ajax

Reading the content of an external file and assigning it to a memory area (identified by its address) Hide the details

<Result> = <File used>.Read(<Number of bytes to read> , <Address>)
<Result>: Integer
  • Number of bytes read,
  • 0 if an error occurs. To get more details on the error, use ErrorInfo with the errMessage constant.
<File used>: DiskFile variable
Name of the DiskFile variable initialized with .Open or Create.
<Number of bytes to read>: Integer
Number of bytes to read (up to 2 147 483 648 bytes).
If the data is a Unicode string, the number of bytes to read corresponds to:
  • in UTF16: the number of characters multiplied by 2.
  • in UTF32: the number of characters multiplied by 4.
<Address>: Address
Address of affected memory section.
Remarks

Handling errors

<DiskFile variable>.Read throws an error in the following cases:
  • the file is not opened,
  • the file is not accessible in read mode,
  • the file is locked by another computer or by another application,
  • the end of the file has been reached.

Position in the file

When opening a file, the current position corresponds to:
  • the first file byte (by default),
  • the last byte of the file is the file is opened in "addition" mode (foAdd constant).
This position can be modified by <DiskFile variable>.Seek.
<DiskFile variable>.Read reads the specified elements from the current position. Once <DiskFile variable>.Read has been executed, the current position is set to the last byte read.
Remark: To always read the beginning of the file, you must call <DiskFile variable>.Seek and then <DiskFile variable>.Read.
Business / UI classification: Business Logic
Component: wd290std.dll
Minimum version required
  • Version 28
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 11/17/2023

Send a report | Local help