Results 1 to 3 of 3
  1. #1
    AkisV is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    Default Stream Corrupted Exception

    Hi I'm having a Stream Corrupted Exception when I'm trying to read from a file:

    Here is my code for reading the file:

    Java Code:
    private String [] loadChordsVector()
        {
            try
            {
                FileInputStream fis = new FileInputStream(FILENAME);
                ObjectInputStream ins = new ObjectInputStream(fis);
                int records  = 0;
                boolean read = true; 
               
               while((Chord)ins.readObject() != null)
                {
    
                    Chord savedChord = (Chord)ins.readObject();//The line for which I get the exception
    
                    chords.add(savedChord);
                }
    
                ins.close();
                
                System.out.println("Records " + records);
                String [] chordNames = new String[chords.size()];
    
                for(int i = 0; i < chords.size(); i++)
                {
                    Chord chord = chords.get(i);
                    chordNames[i] = chord.getName();
                }
                return chordNames;
            }
            
             catch ( EOFException endOfFileException )                 
            {               
                  return null;
            } 
            
            catch (ClassNotFoundException ex) {
                Logger.getLogger(GFriendView.class.getName()).log(Level.SEVERE, null, ex);
                String[] dummy = {"Tesssst"};
                return dummy;
            }
            catch(IOException ioException)
            {
                ioException.printStackTrace();
                JOptionPane.showMessageDialog(null, "Error opening File","Error",JOptionPane.ERROR_MESSAGE );
                String[] dummy = {"Test"};
                return dummy;
        }

    And here is the code with which I save and append to the file:

    Java Code:
    private void SaveActionPerformed(java.awt.event.ActionEvent evt) 
    {
           Vector<PointOnFret> vectorToSave = gPanel1.getFretPointsVector();
           String chordName = JOptionPane.showInputDialog("Enter chord name");
           Chord  chordToSave = new Chord();
           chordToSave.setName(chordName);
           chordToSave.setPositions(vectorToSave);
    
         try{
                FileOutputStream fis = new FileOutputStream(FILENAME,true);
                ObjectOutputStream out = new ObjectOutputStream(fis);
                out.writeObject(chordToSave);
                out.flush();
                out.close();
         }
         catch(IOException ioException)
         {
            JOptionPane.showMessageDialog(null, "Error opening File","Error",JOptionPane.ERROR_MESSAGE );
         }
    
        }

    Can you see something wrong? How can this be fixed?

    Pls help

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    See your other post on the Code Guru forum.

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

    Default

    Hey, I can help you! :D
    well, sort of
    I still cant post URLs, but check this post
    #post44857
    Si vis pasem para bellum
    -Vagecio

Similar Threads

  1. Replies: 1
    Last Post: 03-08-2008, 06:41 PM
  2. JSP- Binary output stream
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-29-2008, 09:06 AM
  3. Replies: 2
    Last Post: 08-07-2007, 03:50 PM
  4. stream redirection
    By Ed in forum New To Java
    Replies: 1
    Last Post: 07-02-2007, 04:34 PM
  5. video stream
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-17-2007, 08:12 AM

Posting Permissions

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