It's not explicitly set—it's determined by the underlying implementation of the C libraries. On Windows, it's the fopen_s function (which is a more secure implementation of fopen). I did a simple test and it appears that if you write plain ASCII to the file, it's saved as plain ASCII. If you write any characters requiring a unicode representation, it's saved as UTF-8 without a BOM (Byte Order Mark). On Linux and Mac OS, fopen is used and the encoding is set to UTF-8 without a BOM whether you write plain text or unicode text.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
How does function (open file writeFile "w") determine the character encoding of the created file ?
I work on windows and I get sometimes "cp1252" and sometimes "UTF-8"
It's not explicitly set—it's determined by the underlying implementation of the C libraries. On Windows, it's the fopen_s function (which is a more secure implementation of fopen). I did a simple test and it appears that if you write plain ASCII to the file, it's saved as plain ASCII. If you write any characters requiring a unicode representation, it's saved as UTF-8 without a BOM (Byte Order Mark). On Linux and Mac OS, fopen is used and the encoding is set to UTF-8 without a BOM whether you write plain text or unicode text.