java为什么已经加了 t不能输出制表位,使用“\t”打印(制表符)不会产生对齐的列...

I have a very weird problem. After writing this:

for (File f : currentFile.listFiles()) {

if (f.isDirectory()){

System.out.println(f.getName()+"\t"+"Dir\t"+Command.getpremission(f)+"\t"+f.getTotalSpace());

}

else{

System.out.println(f.getName()+"\t"+"File\t"+Command.getpremission(f)+"\t"+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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值