Reads from an MS-DOS encoded file or binary file.
[Read :=] File.READ(Variable)
- Type: File Use this variable to refer to the file.
- Type: any The destination variable. You must define the length of the Variable parameter to be greater than or equal to the length of the text in the file that is read, and less than 1024. If the length of the Variable parameter is less than the length of the text in the file, or greater than 1024, then you get the following runtime error:Invalid data encountered in stream, unable to read text. In earlier versions of Microsoft Dynamics NAV, the Variable parameter did not have to be as long as the text in the file. The READ function could read partial data. In Microsoft Dynamics NAV 2013 R2, it is not supported to read fewer than the bytes in the file. If you do not define the length of the Variable parameter, then you get the following runtime error:READ is not supported for Text without a maximum length.
Property Value/Return Value
The number of bytes read.
This return value is optional.
To read from a file that is larger than 1024 bytes, use streams instead of the File.READ function. For more information, see How to: Use Streams to Read from Text Files.
MS-DOS encoding, which is also referred to as OEM encoding, is an older format than UTF-8 and UTF-16, but it is still widely supported. MS-DOS encoding was the only format that was supported by earlier versions of Microsoft Dynamics NAV.
MS-DOS encoding requires a different character set for each language. MS-DOS text is encoded to the internal Unicode data type by using the system locale language of the computer that is running Microsoft Dynamics NAV Server. If you read a file that uses MS-DOS encoding, then you must set the system locale language of the computer that is running Microsoft Dynamics NAV Server to match the language of the data in the file that is being read. For example, if the file contains text in Danish, then you must set the system locale language of the computer that is running Microsoft Dynamics NAV Server to Danish before you call the READ function (FILE) or WRITE Function (File).
We recommend that you use the File data type for files that were created in earlier versions of Microsoft Dynamics NAV.
To read or write files in Unicode or in other formats, we recommend that you use .NET Framework interoperability and use the System.IO Namespace.
The following example opens a text file that is named C:\TestFolder\TestFile.txt. The READ function read the contents of the file and stores it in the String variable. The function returns the size of the text that was read, stores it in the varSize variable, and displays it in a message box. This example assumes that you have created a text file named C:\TestFolder\TestFile.txt that contains less than 500 bytes. This example requires that you create the following variables in the C/AL Globals window.
TestFile.OPEN('C:\TestFolder\TestFile.txt'); varSize := TestFile.READ(String); MESSAGE('The text "%1" is %2 bytes.', String, varSize);