Android Object Serialization writeQueueToFile(Queue list, String filePath)

Here you can find the source of writeQueueToFile(Queue list, String filePath)

Description

write Queue To File

Declaration

public static void writeQueueToFile(Queue list, String filePath) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

import java.util.Queue;

public class Main {

    public static void writeQueueToFile(Queue list, String filePath) {
        if (list == null || filePath == null || filePath.length() == 0)
            return;
        try {//from w w w  . j a v  a 2  s  .  c  o m
            File file = new File(filePath);
            if (!file.exists()) {
                file.getParentFile().mkdirs();
                file.createNewFile();
            }
            ObjectOutputStream oos = new ObjectOutputStream(
                    new FileOutputStream(file, true));
            Object object = list.poll();
            while (object != null) {
                oos.writeObject(object);
                object = list.poll();
            }
            oos.flush();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Related

  1. deserialize(final File file, final long serialTtl)
  2. serialize(final File file, final Object o)
  3. saveObject(Context context, String fileName, Object obj)
  4. writeObjectToFile(Object obj, String filePath)
  5. writeObjectToFile(Object obj, String filePath, boolean append)
  6. ObjectToByte(Serializable obj)
  7. obj2Bytes(Object obj)
  8. obj2Bytes(Object obj)
  9. objectToByte(Object obj)