| | |
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 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






