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輸出文本時更加靈活和方便地進行格式化處理。