Printing with quot;quot; (tabs) does not result in aligned columns(使用“打印(标签)不会导致对齐的列)
问题描述
我有一个非常奇怪的问题.写完之后:
for (File f : currentFile.listFiles()) {if (f.isDirectory()){System.out.println(f.getName()+" "+"Dir "+Command.getpremission(f)+" "+f.getTotalSpace());}别的{System.out.println(f.getName()+" "+"文件 "+Command.getpremission(f)+" "+f.getTotalSpace());}我看到这个打印出来了:
see.txt 文件 rw 267642728448see1.txt 文件 rw 267642728456see2.txt 文件 rw 267642728448为什么标签有问题?
解决方案基于这个问题,我使用以下代码来缩进我的消息:
String prefix1 = "短文本:";字符串前缀 2 = "looooooooooooooong 文本:";String msg = "缩进";/** 第二个字符串在 40 个字符之后开始.破折号表示* 第一个字符串是左对齐的.*/字符串格式 = "%-40s%s%n";System.out.printf(格式,前缀1,味精);System.out.printf(格式,前缀2,味精);这是输出:
<上一页>短文本:缩进looooooooooooooong 文本:缩进
这在 man 3 printf 中的标志字符"部分中有记录.
I have a very weird problem. After writing this:
for (File f : currentFile.listFiles()) {
if (f.isDirectory()){
System.out.println(f.getName()+" "+"Dir "+Command.getpremission(f)+" "+f.getTotalSpace());
}
else{
System.out.println(f.getName()+" "+"File "+Command.getpremission(f)+" "+f.getTotalSpace());
}
I see this printed:
see.txt File rw 267642728448
see1.txt File rw 267642728456
see2.txt File rw 267642728448
Why is there a problem with the tabs?
Building on this question, I use the following code to indent my messages:
String prefix1 = "short text:";
String prefix2 = "looooooooooooooong text:";
String msg = "indented";
/*
* The second string begins after 40 characters. The dash means that the
* first string is left-justified.
*/
String format = "%-40s%s%n";
System.out.printf(format, prefix1, msg);
System.out.printf(format, prefix2, msg);
This is the output:
short text: indented looooooooooooooong text: indented
This is documented in section "Flag characters" in man 3 printf.
这篇关于使用“ "打印(标签)不会导致对齐的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用“ "打印(标签)不会导致对齐的列
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
