| | |
Reading/Writing with ObjectInputStream
![]() |
Hello,
I am having problems using an ObjectInputStream to read from a file. My program uses a File to check whether or not a specific file exists. If it exists my program will attempt to create a FileInputStream for the file and associate an ObjectInputStream with it. It should first read an int, then start reading objects. For some reason it returns an I/O error whenever I attempt to run it.
The file itself is created by using a FileOutputStream and associating an ObjectOutputStream with it. I then write an int and my objects follow that. Any ideas what my problem could be?
The test.tst file is written in such a way that it matches this reading format. If anyone can see an error in how this works I would appreciate it or any sample code I could reference! Thanks!
I am having problems using an ObjectInputStream to read from a file. My program uses a File to check whether or not a specific file exists. If it exists my program will attempt to create a FileInputStream for the file and associate an ObjectInputStream with it. It should first read an int, then start reading objects. For some reason it returns an I/O error whenever I attempt to run it.
The file itself is created by using a FileOutputStream and associating an ObjectOutputStream with it. I then write an int and my objects follow that. Any ideas what my problem could be?
Java Syntax (Toggle Plain Text)
File checkFile = new File("test.tst"); if(checkFile.exists()) { ObjectInputStream readFile = new ObjetInputStream(new FileInputStream("test.tst"); int bushels = readFile.readInt(); BlueBerry firstObject = (BlueBerry) readFile.readObject(); BlueBerry secondObject = (BlueBerry) readFile.readObject(); //.... }
![]() |
Similar Threads
- reading/writing text files question - HELP! (Python)
- help need on file reading and writing in python (Python)
- Reading/Writing To Text File Error (C++)
- question about reading from/writing to a stream (C#)
- pipe reading/writing (C++)
- Help with reading and writing from file (C++)
- Reading/Writing Management Program (C++)
- Reading, Writing and Creating a File (C)
- Reading binary data from a file and writing it (Visual Basic 4 / 5 / 6)
- Need help with my console database app, program reading or writing incorrectly (C++)
Other Threads in the Java Forum
- Previous Thread: Jtext area
- Next Thread: Java accessor naming conventions
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card chat class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting scanner se server service set sms socket software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






