Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing tab characters

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tab characters stored as delemitors in a string like

String str = "\t\t";

When I use Printstream and try to print tab .My intention is to created tab seperations in file but
when i see file comes up like this

M\t\tVIRSA_CC_GENOBJ

But when I use ps.write("\t\t"); (Putting value directly in printstream
My results are correct as expected

M VIRSA_CC_GENOBJ


Is there a way we can get the first case working ?

Thanks in advance




 
Mos Jeff
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tab characters are ASCII characters (ASCII 0x09), not Strings, try using Java's Formatter class through String.format.

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code that causes the wrong output?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Chikara wrote:...when I use ps.write("\t\t"); ... results are correct as expected...

I'm a little confused about how you're successfully using ps.write("\t\t"), because PrintStream's write method using a String parameter is private.

The public write methods take an int or a byte[]. Regarding these, the API says, "Note that the bytes will be written as given; to write characters that will be translated according to the platform's default character encoding, use the print(char) or println(char) methods."

So can you use a print method instead?

The following works for me (using the print method with a String parameter)...

Or am I missing something obvious...?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic