• 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

system.out.println query

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public final class SystemUtil {

private static PrintWriter OUT;
public static PrintWriter out ()
{
if (OUT == null) {
try {
OUT = new PrintWriter(bufferedWriter(System.out, System.getProperty("file.encoding")));
}
catch (UnsupportedEncodingException ex) {
//todo
}
}
return OUT;
}

public static void flushOutput ()
{
if (OUT != null) {
OUT.flush();
}
}

}



1) If I use -> System.out.println("Message");
SystemUtil.flushOutput();
Will this flush System.out ?

2)How System.out.println is different from SystemUtil.out.println

 
Sheriff
Posts: 22783
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

Namrata Maheshwari wrote:1) If I use -> System.out.println("Message");
SystemUtil.flushOutput();
Will this flush System.out ?


Only if ystemUtil.out() has been called before and afterwards nobody called System.setOut to change System.out.

You can flush System.out each time by changing SystemUtil.flushOutput() to call out().flush(). The call to out() will initialize OUT if it's null.

2)How System.out.println is different from SystemUtil.out.println


SystemUtil.out.println() will not compile; you mean SystemUtil.out().println. As far as I know System.out uses the default encoding which should be the same as System.getProperty("file.encoding").
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic