convert Object To String - Android File Input Output

Android examples for File Input Output:Object Serialization

Description

convert Object To String

Demo Code


//package com.java2s;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

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

public class Main {
    public static <E extends Serializable> String convertObjectToString(
            E value) throws IOException {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        ObjectOutputStream o = new ObjectOutputStream(b);
        o.writeObject(value);/*  w  ww .j a v  a  2 s  .  c o  m*/

        byte[] invocationBytes = b.toByteArray();
        o.close();
        b.close();

        String base64 = new String(Base64.encode(invocationBytes,
                Base64.DEFAULT));

        return base64;
    }
}

Related Tutorials