• Post Reply Bookmark Topic Watch Topic
  • New Topic

fileChosevs objectOutpuStream  RSS feed

 
Filipe Pereira
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

At First Head Java they teach how to serialize objects through FileOutPutStream and ObjectOutputStream... But when doing a QUizCardBuilder they use :

BufferedWriter writer = new BufferedWriter(new FileWriter(file)); to searialize the object...

can anyone explain me the diference and how works the BufferedWritermechanism and why they use it instead of FileOutPutStream and ObjectOutputStream??

thanks a lot for the help
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This example isn't using a BufferedWriter to store serialized objects -- it's using it to store Strings as plain text.

InputStreams and OutputStreams are for reading and writing "raw" or binary data, like serialized objects, Word documents, PDF files, etc. Readers and Writers are for reading and writing plain text - *.TXT, *.INI, *.CSV files, etc.
 
Filipe Pereira
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but in the book in page 447, for writing a String to text File we have:

FileWriter writer = new FileWriter("Foo.txt");
writer.write("hello foo");

so why in QuizBuilder i need the BufferedWriter ? Tha why can't i use only write?

that's the part i don't understand... can you help me please? thanks
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the documentation for BufferredWriter.
Writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!