• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList() contents to FileOutputStream >

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic