Description
Checks the encoding of the specified file.
Syntax
FileEncoding ( filename )
Return value
A value of the enumerated datatype encoding. Values are:
EncodingANSI!
EncodingUTF8!
EncodingUTF16LE!
EncodingUTF16BE!
If filename does not exist, returns null.
Usage
Use this function to determine the encoding used in an external file before attempting to use it in a PowerBuilder application.
Examples
The following example opens a file in stream mode and tests to determine whether it uses ANSI encoding. If it does, it reads data from the file into a blob and uses the String function to convert the blob to a Unicode string:
long ll_filenum integer li_bytes string ls_unicode blob lb_ansi encoding eRet ll_filenum = FileOpen("employee.dat", StreamMode!, Read!, LockWrite!, Replace!) // test the file's encoding eRet = FileEncoding("employee.dat") if eRet = EncodingANSI! then li_bytes = FileReadEx(ll_filenum, lb_ansi) ls_unicode = string(lb_ansi, EncodingANSI!) else li_bytes = FileReadEx(ll_filenum, ls_unicode) end if FileClose(ll_filenum)
See also