弹性文件引用保存为 utf-8,采用 BOM 编码格式



我想以 utf-8 编码格式保存文件(不是没有 BOM 的 utf-8)。Adobe Charset 支持页面上没有明确的信息

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

我想将文件保存为带有 csv 扩展名的 utf-8 格式。我已经尝试了以下内容,但我得到了我想要的:

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

我也试过,

Unicode-1-1-UTF-8,Unicode-2-0-UTF-8,x-Unicode-2-0-utf-8.

我也尝试过其他方法,但仍然没有得到所需的编码格式:

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

这是我现在所拥有的,

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);

直觉的答案也对我有帮助。它显示了Java中的答案。以下是我在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);          
}

最新更新