FileReadString can't read more than 8192 bytes (MQL5)

 

I am using the following function in mql5. (which is basically a copy-paste from the documentation  https://docs.mql5.com/files/filereadstring).

Why can't I read more than 8192 bytes from any file? The file read doesn't fail -- it just get's truncated. (No, there is no "\r\n" at location 8192.)

Perhaps @Alain Verleyen or @William Roeder have run into this issue?

string readFile(string InpFileName)

   {

      string str = "";

      ResetLastError();

      int file_handle=FileOpen(InpFileName,FILE_READ|FILE_BIN|FILE_ANSI|FILE_TXT);

      if(file_handle!=INVALID_HANDLE)

        {

         PrintFormat("%s file is available for reading",InpFileName);

         PrintFormat("File path: %s\\MQL5\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));

         //--- additional variables

         int    str_size;

         //--- read data from the file

         while(!FileIsEnding(file_handle))

           {

            str_size=FileReadInteger(file_handle,INT_VALUE);

            //--- read the string

            str+=FileReadString(file_handle,str_size);

           }

           Print(str);

         //--- close the file

         FileClose(file_handle);

         PrintFormat("Data is read, %s file is closed",InpFileName);

        }

      else

         PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());

         return(str);

         

    }
FileReadString - File Functions - MQL4 Reference
FileReadString - File Functions - MQL4 Reference
  • docs.mql4.com
When reading from a bin-file. the length of a string to read must be specified. When reading from a txt-file the string length is not required, and the string will be read from the current position to the line feed character "\r\n". When reading from a csv-file, the string length isn't required also, the string will be read from the current...
 
int file_handle=FileOpen(InpFileName,FILE_READ|FILE_BIN|FILE_ANSI|FILE_TXT);
  1. A file can be binary or it can be text. It can't be both.
  2. FileReadString only works with binary files.
Reason: