writing arraylist of objects in file
<p>I want to write arraylist of objects in a file. But only one object in going in file.Atfirst I am fetching all the stored objects and then appending new object after that I write whole arrayList to the file.</p>

<p>Here is my code....</p>

<pre><code>public void write(UserDetail u1) throws FileNotFoundException {
    ArrayList&lt;UserDetail&gt; al = new ArrayList&lt;UserDetail&gt;();
    FileInputStream fin = new FileInputStream(FILEPATH);

    try {

        if (fin.available() != 0) {
            ObjectInputStream ois = new ObjectInputStream(fin);
            while (fin.available() != 0 &amp;&amp; ois.available() != 0) {
                try {
                    al.add((UserDetail) ois.readObject());

                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {

                    if (ois != null) {
                        ois.close();

                    }
                }
            }
        }
        al.add(u1);
        FileOutputStream fos = new FileOutputStream(FILEPATH);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(al);
        oos.flush();
        oos.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        throw e;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
</code></pre>

<p>help me......thnx in advance</p>
