convert String To Object - Android File Input Output

Android examples for File Input Output:Object Serialization

Description

convert String To Object

Demo Code


//package com.java2s;
import java.io.ByteArrayInputStream;

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

import java.io.OptionalDataException;
import java.io.Serializable;
import android.util.Base64;

public class Main {
    @SuppressWarnings("unchecked")
    public static <E extends Serializable> E convertStringToObject(
            String base64) throws OptionalDataException,
            ClassNotFoundException, IOException {
        byte[] bytes = Base64.decode(base64, Base64.DEFAULT);
        ByteArrayInputStream b = new ByteArrayInputStream(bytes);
        ObjectInputStream o = new ObjectInputStream(b);

        Object object = o.readObject();
        b.close();//  w  w w.java  2  s  .  c om
        o.close();

        return (E) object;
    }
}

Related Tutorials