问题
This is what I have tryed to do:
String raw = dstream.readLine();
raw = raw.replaceAll("Up"," ↑ ");
raw = raw.replaceAll("Right"," → ");
System.out.println(raw);
This is part of an easy program that receives Strings and prints them to a text file: "java -jar Server.jar > a.txt".
The problem is this:
Insted of ↑ or → , I get those in the txt file: "↕ ↕ ↕ ↑"
回答1:
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.
来源:https://stackoverflow.com/questions/49886402/how-can-i-print-symbols-from-a-string-to-a-txt-file