I need to generate text data files, both with UTF-8 byte-order-mark and without it. How do I do that?
So far the file has been generated like this:
File(fileName).writeText(source, Charsets.UTF_8)
But this does not provides the possibility to have the BOM on demand.
Note 1:
In this question How to add a UTF-8 BOM in java are using BufferedWriter
and PrintStream.print()
, but this implies to change the generation of the code to a more Java-oriented way (this is the last option).
Note 2:
In this other question Java: UTF-8 and BOM from 2012, points to a Java Bug that the BOM is not handle. In the comments suggest to never use BOM, but this is not an option in my case because the files are send to different services some of which require it and others don't. Does anybody knows more recent news about this? and if applies to Kotlin?