• Post Reply Bookmark Topic Watch Topic
  • New Topic

system.out.println query  RSS feed

 
Namrata Maheshwari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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

 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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").
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!