4 Replies - 3628 Views - Last Post: 29 March 2012 - 01:22 PM Rate Topic: -----

#1 EthanR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-March 09

Difference between PrintWriter.write() and System.out.print()

Posted 28 March 2012 - 02:02 PM

I am wondering what the difference between the output of PrintWriter.write() and System.out.print(). I have gotten two different results when dealing with very large amounts of output.
Is This A Good Question/Topic? 0
  • +

Replies To: Difference between PrintWriter.write() and System.out.print()

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Difference between PrintWriter.write() and System.out.print()

Posted 28 March 2012 - 02:15 PM

Usually a PrintWriter is used to write to a File and System.out.println() to the console.

I don't see the utility of making a new PrintWriter(System.out) unless may be if the Output Stream is received as parameter to a method. In that case your code would be the same for both writing to a file or writing to a console the OuputStream being passed as parameter to the method.

What differences did you see ?
Was This Post Helpful? 1
  • +
  • -

#3 EthanR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-March 09

Re: Difference between PrintWriter.write() and System.out.print()

Posted 28 March 2012 - 02:33 PM

The difference I have seen is if I print out to the console I print the entire amount of data that I am trying to print, where as when I try to write out to the file I write the entire amount of data except for the very last bit of data.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Difference between PrintWriter.write() and System.out.print()

Posted 28 March 2012 - 09:11 PM

what do you call

Quote

last bit of data
?
Do you close your PrintWriter because tring to read the data into it ?
Was This Post Helpful? 1
  • +
  • -

#5 EthanR  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-March 09

Re: Difference between PrintWriter.write() and System.out.print()

Posted 29 March 2012 - 01:22 PM

Yep it was me forgetting to close the PrintWriter, thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1