这个问题在这里已有答案:
我有一个文字像:
DISK_ERROR_MESSAGE = "Server %s is using more than 90% of the disk."
问题是,当我尝试做类似的事情:
String.format(DISK_ERROR_MESSAGE,host.getName())
Java启动错误:
Method threw 'java.util.MissingFormatArgumentException' exception.
java.util.MissingFormatArgumentException: Format specifier '% o'
问题是90%的百分比。
但我不知道如何避免它,而不分开两个字符串中的文本。
要逃离%
,你需要加倍:%%
。
因此,您需要将字符串更改为
DISK_ERROR_MESSAGE = "Server %s is using more than 90%% of the disk."