tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > IO > DeSerialize object from file

DeSerialize object from file 

The following example shows how to deserialize list of strings from a flat file.

File Name  :  
com/bethecoder/tutorials/io/ObjectInputStreamTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;

public class ObjectInputStreamTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    try {
      List<String> list = null;
      
      ObjectInputStream input = 
        new ObjectInputStream(new FileInputStream("C:\\example.ser"));
      
      list = (List<String>input.readObject();
      input.close();
      
      System.out.println("list : " + list);
      
    catch (FileNotFoundException e) {
      e.printStackTrace();
    catch (IOException e) {
      e.printStackTrace();
    catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }

}
   

It gives the following output,
list : [ONE, TWO, THREE, FOUR, FIVE, SIX]



 
  


  
bl  br