在java中写单个字符的奇怪行为
我正在尝试在文本文件中写入单个字符。
我这样做:
BufferedWriter out = new BufferedWriter(new FileWriter("exemple.txt"));
out.write((char)174);
out.close();
如果我用二进制查看器查看,我的文本文件应该包含 10101110。相反,它显示 11000010 10101110。因此它写入 194 174,这不是预期的结果。
那么我怎样才能在java中编写一个字符来产生好的二进制值呢?
I am trying to write a single character in a text file.
I do:
BufferedWriter out = new BufferedWriter(new FileWriter("exemple.txt"));
out.write((char)174);
out.close();
My text file is supposed to contains 10101110, if I look it with a binary viewer. Instead of it, it shows 11000010 10101110. So it writes 194 174, which is not the expected result.
So how can I write a single character in java which will result the good binary value ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用适当的字符集打开文件。比如:
我建议阅读一个很好的教程,它讲述了字节和字符之间的区别以及字符集是什么。
You need to open the file using the appropriate character set. something like:
i would suggest reading a good tutorial which teaches the difference between bytes and chars and what a character set is.