JFile::write uses the file_put_contents PHP function. even if not clearly explained by the PHP manual the "file_put_contents" automatically detects the encoding of the content to write and automatically setup the file format.
I did few tests and research to understand if it is possible to FORCE JFile::write / file_put_contents to use "UTF-8 without BOM" format
Apparently there is NO WAY (unbelievable!!!) to explicitly setup that format independently by the content to write.
The simplest workaround and trick I found, to create files with format "UTF-8 without BOM" is to add (even as comment) some UTF-8 characters (note: one character is not enough), for example add this string anywhere in the file (as commented line):
؋ 包 ƒ ман лв ¥ ₡ ₱ ¢ ₪ ₹ ﷼ ៛ ₩ ₭ ₮ ₨ ₴ ₫
and magically the file created will be "UTF-8 without BOM".
It's weird but I didn't find any other simple way to generate files with that format! unbelievable!
I'm sure you know the importance to have "UTF-8 without BOM" files instead of ANSI, but just to clarify to the other users, it allow us to use UTF-8 characters inside the file and therefore into the generated webpages.
A common use would be in language files, if we think about chinese, arabic, greek or even italian and french (accented vocals), or NOT-ENGLISH code comments, these would be something common, but there are other cases where the "UTF-8 without BOM" file format is needed.