load List from AtomicFile - Android android.support.v4.util

Android examples for android.support.v4.util:AtomicFile

Description

load List from AtomicFile

Demo Code


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

import java.io.ObjectInputStream;

import java.util.List;
import android.support.v4.util.AtomicFile;

public class Main {
    public static <T> List<T> loadList(File file) throws Exception {
        AtomicFile atom = new AtomicFile(file);
        FileInputStream stream = atom.openRead();
        try {/*from   w  ww.j  a va 2  s  .co  m*/
            ObjectInputStream in = new ObjectInputStream(stream);
            return (List<T>) in.readObject();
        } finally {
            stream.close();
        }
    }
}

Related Tutorials