File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes overriding System.out.format(), doesnt work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "overriding System.out.format(), doesnt work" Watch "overriding System.out.format(), doesnt work" New topic
Author

overriding System.out.format(), doesnt work

Paul dearrt
Greenhorn

Joined: Apr 22, 2011
Posts: 6
Hi,
how i can override method PrintStream format(format, args)?

I made
and System.setOut(ps);

but method format doesnt work, any idea?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Apr 22, 2011
Posts: 6
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.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19695
    
  20

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...


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding System.out.format(), doesnt work