📅  最后修改于: 2020-11-14 06:16:10             🧑  作者: Mango
java.util.Formatter类提供了对布局对齐和对齐,数字,字符串和日期/时间数据的通用格式以及特定于语言环境的输出的支持。以下是有关Formatter的重点-
格式化程序对于多线程访问不一定是安全的。线程安全是可选的,并且是此类中用户的责任。
以下是java.util.Formatter类的声明-
public final class Formatter
extends Object
implements Closeable, Flushable
Sr.No. | Constructor & Description |
---|---|
1 |
Formatter() This constructor constructs a new formatter. |
2 |
Formatter(Appendable a) This constructor constructs a new formatter with the specified destination. |
3 |
Formatter(Appendable a, Locale l) This constructor constructs a new formatter with the specified destination and locale. |
4 |
Formatter(File file) This constructor constructs a new formatter with the specified file. |
5 |
Formatter(File file, String csn) This constructor constructs a new formatter with the specified file and charset. |
6 |
Formatter(File file, String csn, Locale l) This constructor constructs a new formatter with the specified file, charset, and locale. |
7 |
Formatter(Locale l) This constructor constructs a new formatter with the specified locale. |
8 |
Formatter(OutputStream os) This constructor constructs a new formatter with the specified output stream. |
9 |
Formatter(OutputStream os, String csn) This constructor constructs a new formatter with the specified output stream and charset. |
10 |
Formatter(OutputStream os, String csn, Locale l) This constructor constructs a new formatter with the specified output stream, charset, and locale. |
11 |
Formatter(PrintStream ps) This constructor constructs a new formatter with the specified print stream. |
12 |
Formatter(String fileName) This constructor constructs a new formatter with the specified file name. |
13 |
Formatter(String fileName, String csn) This constructor constructs a new formatter with the specified file name and charset. |
14 |
Formatter(String fileName, String csn, Locale l) This constructor constructs a new formatter with the specified file name, charset, and locale. |
Sr.No. | Method & Description |
---|---|
1 | void close()
This method closes this formatter. |
2 | void flush()
This method flushes this formatter. |
3 | Formatter format(Locale l, String format, Object… args)
This method writes a formatted string to this object’s destination using the specified locale, format string, and arguments. |
4 | Formatter format(String format, Object… args)
This method writes a formatted string to this object’s destination using the specified format string and arguments. |
5 | IOException ioException()
This method returns the IOException last thrown by this formatter’s Appendable. |
6 | Locale locale()
This method returns the locale set by the construction of this formatter. |
7 | Appendable out()
This method returns the destination for the output. |
8 | String toString()
This method returns the result of invoking toString() on the destination for the output. |
此类从以下类继承方法-