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输出文本时更加灵活和方便地进行格式化处理。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:C++ logger的输出格式化