Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Goodwine

Thread: I got a problem with StreamCorruptedException, any ideas?

  1. #1
    Goodwine's Avatar
    Goodwine is offline Member
    Join Date
    Nov 2008
    Location
    Mexico
    Posts
    14
    Rep Power
    0

    Unhappy [Solved] StreamCorruptedException

    Hello, I found the reason for this exception, see my post below, it explains how
    Java Code:
    java.io.StreamCorruptedException: invalid type code: AC
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1356)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at Usuario.checkExistance(Usuario.java:72)
        at Usuario.escribir(Usuario.java:44)
        at Master.escribir(Master.java:9)
        at BancoMain.main(BancoMain.java:11)
    Usuario creado Satisfactoriamente
    Process completed.
    any ideas what to do here?:confused: im really stuck in here :s
    obviously my problem is when it tries to read the second object, it throws the exception there
    Last edited by Goodwine; 11-24-2008 at 07:23 AM. Reason: Found the reason of my problem
    Si vis pasem para bellum
    -Vagecio

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    No es correcto:
    Java Code:
    if(checkExistance(fileName, objeto))
    return "El Usuario ya existe";
    Que quiere vuelta? Entrada try{ mas pronto.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Goodwine's Avatar
    Goodwine is offline Member
    Join Date
    Nov 2008
    Location
    Mexico
    Posts
    14
    Rep Power
    0

    Default

    Nope u.u
    I get the same error,
    My problem is to read objects from file on
    Java Code:
    while(true)
    {
    	user = null;
    	user = (Usuario)objIn.readObject(); //the second time i go thru here, it throws an exception
    	if (user.getCuenta ().equals (objeto.getCuenta ()))
    		return true;
    }
    Si vis pasem para bellum
    -Vagecio

  4. #4
    Goodwine's Avatar
    Goodwine is offline Member
    Join Date
    Nov 2008
    Location
    Mexico
    Posts
    14
    Rep Power
    0

    Default

    Well, after investigating a lot, going thru many test, etc, i found the cause is really simple
    ObjectInputStream does not accept appending objects on the last of the file xD!
    if any one gets the same problem, stop appending, it wont work there :(
    I thought on creating a vector, put every object in the file there, then add extraobjects to the end of the vector and finally write everything back
    Si vis pasem para bellum
    -Vagecio

  5. #5
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by Goodwine View Post
    Well, after investigating a lot, going thru many test, etc, i found the cause is really simple
    ObjectInputStream does not accept appending objects on the last of the file xD!
    if any one gets the same problem, stop appending, it wont work there :(
    I thought on creating a vector, put every object in the file there, then add extraobjects to the end of the vector and finally write everything back
    Hi..I'm facing a similar problem :( ... Can you please show the code where you added the fix to solve this issue......or you can drop a message......Thanks in advance :o
    Cristo Haris :)

  6. #6
    Goodwine's Avatar
    Goodwine is offline Member
    Join Date
    Nov 2008
    Location
    Mexico
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by cristo_haris View Post
    Hi..I'm facing a similar problem :( ... Can you please show the code where you added the fix to solve this issue......or you can drop a message......Thanks in advance :o
    Look, I really don't remember what was the code but hopefully this helps you out:

    I think this is what happens... if you append with ObjectOutputStream, you will append after EoF and not before. So, when you are reading the objects with ObjectInputStream you will have this exception thrown when it reaches EoF and you still ask for an Object.

    You can fix it by reading all objects in a vector, adding the new object in the vector, and finally overwriting the file. I do not recommend doing this but it will be an easy and fast way of fixing the problem.

    Try using something like DataOutputStream
    and write line by line, and to read it you will do the same, line by line
    In this case I recommend you use some kind of identification code, so you will first browse the file in search of the line and when you find the id you will read the next lines that are needed to create an object.
    srikanth.pm likes this.
    Si vis pasem para bellum
    -Vagecio

  7. #7
    cristo_haris is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by Goodwine View Post
    Look, I really don't remember what was the code but hopefully this helps you out:

    I think this is what happens... if you append with ObjectOutputStream, you will append after EoF and not before. So, when you are reading the objects with ObjectInputStream you will have this exception thrown when it reaches EoF and you still ask for an Object.

    You can fix it by reading all objects in a vector, adding the new object in the vector, and finally overwriting the file. I do not recommend doing this but it will be an easy and fast way of fixing the problem.

    Try using something like DataOutputStream
    and write line by line, and to read it you will do the same, line by line
    In this case I recommend you use some kind of identification code, so you will first browse the file in search of the line and when you find the id you will read the next lines that are needed to create an object.
    ok thanks, anyway the issue was fixed in another way...
    Cristo Haris :)

  8. #8
    mcherkao is offline Member
    Join Date
    Sep 2010
    Posts
    7
    Rep Power
    0

    Default

    which way ? I ve also the same problem.

  9. #9
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    This thread was started almost two years ago, and the last reply was eighteen months ago.

    If you're having an issue, please start a new thread.

Similar Threads

  1. Any ideas to create a filter program?
    By paulachrist in forum New To Java
    Replies: 4
    Last Post: 07-11-2008, 04:53 AM
  2. Java Performance Ideas
    By developer321 in forum Advanced Java
    Replies: 4
    Last Post: 06-28-2008, 05:16 PM
  3. Merging Ideas
    By CompleteBeginner in forum New To Java
    Replies: 1
    Last Post: 05-19-2008, 03:15 PM
  4. java.io.StreamCorruptedException
    By elizabeth in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 07:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •