我有一个类似:
的文字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."