Flex 3 / Air:使用 FileStream 将空白新行写入文件
我想使用 Flex 3 / Air 将一些文本直接写入文件。文件上的文本(称为“Database.txt”)必须具有以下格式:
Line1
Line2
Line3
var FS:FileStream = new FileStream();
var DatabaseFile:File = File.desktopDirectory.resolvePath("Database.txt");
FS.open(DatabaseFile, FileMode.WRITE);
FS.writeUTFBytes("Line1" + "\n" + "Line2" + "\n" + "Line3");
FS.close();
但它将以下文本写入文件:
Line1 Line2 Line3。
我很确定我犯了一个非常愚蠢的错误,但我无法弄清楚它是什么。谁能帮助我吗?
谢谢您的宝贵时间:)
I want to write some text directly to a file using Flex 3 / Air. The text on the file (call it "Database.txt") must have the following format:
Line1
Line2
Line3
var FS:FileStream = new FileStream();
var DatabaseFile:File = File.desktopDirectory.resolvePath("Database.txt");
FS.open(DatabaseFile, FileMode.WRITE);
FS.writeUTFBytes("Line1" + "\n" + "Line2" + "\n" + "Line3");
FS.close();
But it writes the following text to the file:
Line1 Line2 Line3.
I'm pretty sure I'm making a very dummy error, but I cannot figure out what it is. Can anyone help me?
Thank you for your time :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你如何打开Database.txt?如果您使用的是 notepad.exe,它将全部显示在一行上,因为 notepad.exe 速度较慢且不支持 UNIX 行结尾 (
\n
)。如果您确实需要在 notepad.exe 中打开它,则需要使用 Windows 行结尾 (\r\n
)。因此,您的代码将如下所示:但现在您还必须确保您的代码在将 txt 文件加载回 AIR 应用程序时可以处理这些 Windows 行结尾(否则您可能会得到重复的行)
How are you opening Database.txt? If you are using notepad.exe, it will appear all on one line, since notepad.exe is retarded and doesn't support unix line endings (
\n
). If you absolutely need it to be opened in notepad.exe, what you need to do is use windows line endings instead (\r\n
). So your code would look like:But now you also have to make sure your code can handle these windows line endings when loading the txt file back into your AIR application (or you might end up with duplicate lines)
FS.writeUTFBytes("Line1" + File.lineEnding + "Line2" + File.lineEnding + "Line3");
FS.writeUTFBytes("Line1" + File.lineEnding + "Line2" + File.lineEnding + "Line3");