aspose file tools*
The moose likes Beginning Java and the fly likes print tab help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "print tab help" Watch "print tab help" New topic
Author

print tab help

Ellen fish
Greenhorn

Joined: Oct 28, 2008
Posts: 27
Hello,
when I do:
System.out.println("out.txts\t\t"+"asdf");
System.out.println("out.txt\t\t"+"asdf");

I get:
out.txtsasdf
out.txtasdf

Is there a way to align the two print result without adding an extra \t for out.txt?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

Check out PrintStream's printf method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ellen fish
Greenhorn

Joined: Oct 28, 2008
Posts: 27
mm..printf doesn't seem to help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36574
    
  16
Yes, it would, if you used the numbers which set the width of the fields. There are full details in Formatter, and details you can actually understand ( ) in the Java Tutorials.
Ellen fish
Greenhorn

Joined: Oct 28, 2008
Posts: 27
hm...another thing I forgot to mention is that I'm using
StringBuffer str = new StringBuffer();
and str.append to connect all the strings together and print out in the end.
I have tried but still couldn't find a way with formater ><
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: print tab help
 
Similar Threads
casting string
Complicated string problem
awk: cmd. line:1: (FILENAME=out.txt FNR=1) fatal: division by zero attempted
display image in fixed place
align output with StringBuffer