字符串保存到文本在AS3文件 [英] Saving string to text file in AS3

查看:155
本文介绍了字符串保存到文本在AS3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数的字符串写入到一个文本文件中。它的工作原理,但由于某些原因(编码?)它增加了一些奇怪的数据的文件的开头。

I have a function for writing String to a text file. It works, but for some reason (encoding?) it adds some weird data to the beginning of the file.

下面是相关code:

    var file:File =  new File(OUTPUT_FILE_NAME);
    var stream:FileStream = new FileStream();
    stream.open(file, FileMode.WRITE);
    stream.writeUTF("Hello World!");
    stream.close();

当我打开记事本+ +的文件,它显示了这一点:

When I open the file in Notepad++, it shows this:

我是什么做错了吗?

推荐答案

使用 stream.writeUTFBytes(的Hello World); 而不是 stream.writeUTF(的Hello World!);

如果我们使用 writeUTF 然后把它写preFIX的字符串与16位长度的词。如果你使用 writeUTFBytes 则省略此preFIX长度的字符串。

if we use writeUTF then it write prefix the string with a 16-bit length word. if you use writeUTFBytes then it omit this prefix Length String.

这篇关于字符串保存到文本在AS3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆