If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Now my problem is that when I try to read objects continously, I am able to read only the first written object. While writing "Orglist.lekha" append= true. so even if I have written more than one object I am not able to read it back. I am getting following error in my second run of the while() loop. Please help me with this because I am stuck here and my work is not proceeding.

Objects from file in a loop

Have you looked at a more direct test as the while test, rather than the flag?

The ObjectInputStream has a read() method which returns an integer representation of the next available byte - which returns -1 if you have reached the end of the file. Now, as long as when you read the next byte you do not discard that next byte, you can test for -1 at the top of the loop, then do a readObject() to get the next object, return to the top of the loop and test for the end again, then read another Object if you can, etc.

As an alternative you might be able to use the available() method to tell you that you still have stuff in the input buffer:

Thanks for the quick reply
I tried what you have suggested but it is again giving me StreamCorruptedException. First it is not going in side the while loop, so I tried do while loop. here it reads the first record and then duing the second run of loop it is giving me the error. Can you please suggest me some other way to acheive the required task.

Even at the first run of loop or even simply read() or available() returns -1 and 0 respectively. Tried using two seperate try catch blocks no avail. Do you think I am making mistake while writing objects.

Hi friends,
First of all thank you for all the people, I have been working on this problem for all most a week from now. And I have come up with an answer. It seem that ObjectStream in java does not allow to read objects written into a file as I have done. Please refer to my first post. So i figured out that if it does not allow to read multiple objects why not use only one object, and let this object contain all the other objects.
One such implementation would be to use vectors.
What I did is I declared a vector and then I inserted all the objects I wanted to write to file into this vector. After this I wrote this vector object to file. While reading it back I read it to a vector. By this I was able to solve my problem.
thank you
bye