PrintWriter out = new PrintWriter(System.out);
out.printf("Hello, %s! You have %d new messages.", "Alice", 5);
PrintWriter out = new PrintWriter(System.out);
String formatted = String.format("Hello, %s! You have %d new messages.", "Alice", 5);
out.print(formatted);
PrintWriter out = new PrintWriter(System.out);
Formatter formatter = new Formatter(out);
formatter.format("Hello, %s! You have %d new messages.", "Alice", 5);
formatter.close();
这些技巧可以帮助你在使用PrintWriter输出文本时更加灵活和方便地进行格式化处理。