• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Printing tab characters

 
Ranch Hand
Posts: 413
  • 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




 
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.

 
Bartender
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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • 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...?
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic