Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将三个字符串写入一个没有任何新行的文件,并将它们放在固定宽度的字段中。目前我正在尝试使用 printwriter 的 printf,但我不完全理解如何去做。如果这不是足够的信息,请询问并尽我所能澄清我的问题。
如果你有 3 个字符串,a、b 和 c,你应该能够使用这样的东西......
printf("a=%-20s b=%-20s c=%-20s", a, b, c);
这将使您的字符串左对齐,并且它们将被固定为每个 20 的宽度。