Java ObjectOutputStream Write load(File file)

Here you can find the source of load(File file)

Description

load

License

Open Source License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
IOException an exception
ClassNotFoundException an exception

Return

Object

Declaration

public static Object load(File file) throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

public class Main {
    /**// w  w  w  .  j a va 2 s .  co  m
     * @param file
     * @return Object
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static Object load(File file) throws IOException, ClassNotFoundException {
        FileInputStream fis = null;
        ObjectInputStream ois = null;
        try {
            fis = new FileInputStream(file);
            ois = new ObjectInputStream(fis);
            return ois.readObject();
        } finally {
            try {
                if (ois != null) {
                    ois.close();
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                // Do Nothing
            }
        }
    }
}

Related

  1. load(File f)
  2. load(File file)
  3. load(File file, Class type)
  4. load(File file, final ClassLoader... loaders)
  5. load(String fileName)