【问题标题】:Flex fileReference save in utf-8 with BOM encoding formatFlex fileReference 以 utf-8 格式保存为 BOM 编码格式
【发布时间】:2012-05-19 16:24:48
【问题描述】:

我想以 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);

【问题讨论】:

标签: apache-flex utf-8 character-encoding byte-order-mark


【解决方案1】:

intuidev 的答案也对我有帮助。它用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);          
}

【讨论】:

    猜你喜欢
    • 2016-09-08
    • 2014-08-30
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    相关资源
    最近更新 更多