Here you can find the source of writeQueueToFile(Queue list, String filePath)
public static void writeQueueToFile(Queue list, String filePath)
//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(); } } }