Question

I want to save a file in utf-8 encoding format (NOT utf-8 without BOM). There is no explicit information on Adobe Charset support page

(http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/charset-codes.html)

I want to save the file in utf-8 format with csv extension. I have tried the following but i am getting what i want:

byte.writeMultiBytes(fileContent,"utf-8");

I have also tried,

unicode-1-1-utf-8, unicode-2-0-utf-8, x-unicode-2-0-utf-8.

I have also tried with other methods as well but still not getting the required encoding format:

writeUTF(var:String) writeByte(var:String)

Here's what I have right now,

var fileReference:FileReference = new FileReference();  
var bytes:ByteArray = new ByteArray();

// SAVING file in utf-8 encoding format.
bytes.writeUTFBytes(this.fileContents);
fileReference.save(bytes, "PluginLog.csv");
closePopup(null);
Was it helpful?

Solution

The answer intuidev points to helped me as well. It shows the answer in Java. Here's how I reproduced it in Actionscript:

public function writeFileWithUTF8Bom(data:String, fileName:String):void {
    var fileRef:FileReference = new FileReference();
    var b:ByteArray = new ByteArray();
    // Include the byte order mark for UTF-8
    b.writeByte(0xEF);
    b.writeByte(0xBB);
    b.writeByte(0xBF);
    b.writeUTFBytes(data);
    fileRef.save(b, fileName);          
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top