Results 1 to 3 of 3
Thread: Stream Corrupted Exception
- 10-01-2008, 08:47 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 2
- Rep Power
- 0
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
- 10-01-2008, 11:31 PM #2
See your other post on the Code Guru forum.
- 11-24-2008, 06:25 AM #3
Similar Threads
-
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM -
JSP- Binary output stream
By Java Tip in forum Java TipReplies: 0Last Post: 01-29-2008, 09:06 AM -
java.lang.NumberFormatException: For input stream:jav
By osval in forum New To JavaReplies: 2Last Post: 08-07-2007, 03:50 PM -
stream redirection
By Ed in forum New To JavaReplies: 1Last Post: 07-02-2007, 04:34 PM -
video stream
By Alan in forum Advanced JavaReplies: 2Last Post: 05-17-2007, 08:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks