Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList() contents to FileOutputStream >  RSS feed

 
Akash Kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
While taking one of the parctice test I stuck in the following code. Can anybody help me to figure the correct amswer:

FileOutputStream f=new FileOutputStream("TestSerial");
List alist=new ArrayList();
/* .. ....... */
// Serialize list 'alist' and all its contents to stream f.
// Blank
Which one of the following lines of code will serialize list 'alist' and all its contents to FileOutputStream f when substituted for Blank Line in the code above?
Ans. 1. new ObjectOutputStream(f).writeObject(alist);
2. f.write(new ByteOutputStream(alist);
3. new BufferedOutputStream(f).write(alist.toStream());
4. Object.writeObjectToStream(f,alist);
5. alist.writeToByteStream(new ByteOutputStream(f));

Thanks in advance
Akash
 
feng chou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please look at these code:
ObjectOutputStream o=new ObjectOutputStream(f);
//decorate the FileOutputStream.
o.writeObject(alist);
//so you can use writeObject() to serialize an
//Arraylist.
so the answer is 1.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!