| | |
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 |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows






