如何将字符串中的符号打印到 txt 文件? [英] How can I print symbols from a String to a txt file?
本文介绍了如何将字符串中的符号打印到 txt 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我尝试做的:
String raw = dstream.readLine();
raw = raw.replaceAll("Up"," ↑ ");
raw = raw.replaceAll("Right"," → ");
System.out.println(raw);
这是一个简单程序的一部分,它接收字符串并将它们打印到一个文本文件中:java -jar Server.jar > a.txt".
This is part of an easy program that receives Strings and prints them to a text file: "java -jar Server.jar > a.txt".
问题是这样的:
插入 ↑ 或 → ,我在 txt 文件中得到这些:↕ ↕ ↕ ↑"
The problem is this:
Insted of ↑ or → , I get those in the txt file: "↕ ↕ ↕ ↑"
推荐答案
cat Upright.java
public class Upright
{
public static void main (String args[])
{
String raw ="Left - Down - Up - Right - East - West";
raw = raw.replaceAll("Up"," ↑ ");
raw = raw.replaceAll("Right"," → ");
System.out.println(raw);
}
}
java Upright > upright.txt && cat upright.txt
Left - Down - ↑ - → - East - West
就像一个魅力.用于生成源代码的工具的字符编码必须与查看输出文件的工具相匹配.
Works like a charm. The character encoding of the tool, you use to produce the source, has to match the tool for looking at the output file.
这篇关于如何将字符串中的符号打印到 txt 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文