本文介紹了使用“ "打印(標簽)不會導致對齊的列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個非常奇怪的問題.寫完之后:
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
.
這篇關于使用“ "打印(標簽)不會導致對齊的列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!