• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overriding System.out.format(), doesnt work

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
how i can override method PrintStream format(format, args)?

I made
and System.setOut(ps);

but method format doesnt work, any idea?
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would start by finding out what "doesn't work" means. Have a look at our FAQ entry ItDoesntWorkIsUseless for tips on how to do that.

Also, I wrapped your posted code in the "Code" tags for you. See how much easier it is to read now? To do that, just select your code after you paste it into the posting box and click the "Code" button you'll see above the box.
 
Paul dearrt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I would start by finding out what "doesn't work" means. Have a look at our FAQ entry ItDoesntWorkIsUseless for tips on how to do that.

Also, I wrapped your posted code in the "Code" tags for you. See how much easier it is to read now? To do that, just select your code after you paste it into the posting box and click the "Code" button you'll see above the box.



Im sorry, I was in hurry.
Doesnt work in this case means: dont formatting text; it only print to PrintStream, without formatting.

 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think that format uses println or print? It's not documented anywhere.

I've checked the source code of PrintStream (just check the src.zip file in your JDK folder), and format treats the PrintStream as an Appender. That means that you would need to override all of the append methods:
That still doesn't mean all methods work. You need to override all of the other print and println methods as well, as these each call a private method called write (and the println methods also a private method called newLine()) which you cannot override. In other words, you'll probably have to override every single method...
reply
    Bookmark Topic Watch Topic
  • New Topic