Suvam Roy Suvam Roy - 6 months ago 26
Java Question

What is the use of true in PrintWriter object?

In a code I came accross the code was like

PrintWriter pw=new PrintWriter(System.out,true)

In another program of socket in java also saw the same i.e

PrintWriter pw=new PrintWriter(s.getOutputStream,true)

Now what is the function of true? As far my knowledge we use true to append something with the file content that already exist. If we don't use true then the file content will be overwritten. Am I right? But in Oracle site they said true is used to enable autoflush. Please clarify the acquisition.

Answer Source

In PrintWriter true is the indication of autoflush that's all. If you didn't set autoflush true then you would have to explicitely do pw.flush();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download