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?
The Escape sequence for tab, \t can be used inside a print statement, as given in the code below. The String to be formatted is placed inside the double quotes. The Escape Sequence for tab \t is placed between the words inside the "" . As we can see in the output, it inserts a tab between the two words.
The easiest way to print a tab character in Python is to use the short-hand abbreviation '\t' . To see the tab spaced character in the REPL wrap any variable containing a tab character in the built-in print() function.
When you are printing a tab character to the standard output using printf in C, it outputs some space which is apparently 4 characters in length. printf("\t");
"\t" format specifier is used in println() function to leave tab space in the console.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With