| | |
IOException when opening FileInputStream
![]() |
Hello,
I am writing a method which must open a file, read its contents, close the file, open it later, write to the file, and close it again. The method is failing at the first step and throwing an IOException when trying to execute:
I am somewhat baffled as to why this is occurring. The file is in the proper directory, it is not in use, and the other handlers to it are closed before this call is made to it. Any ideas as to what is going on? Thanks!
I am writing a method which must open a file, read its contents, close the file, open it later, write to the file, and close it again. The method is failing at the first step and throwing an IOException when trying to execute:
Java Syntax (Toggle Plain Text)
FileInput Stream fileHandler = new FileInputStream("myfile.fil");
I hope that is supposed to be:
furthermore, that constructor should not be throwing any IOExceptions, do you have more code or the rest of the exception stack trace?
java Syntax (Toggle Plain Text)
FileInputStream fileHandler = new FileInputStream("myfile.fil");
furthermore, that constructor should not be throwing any IOExceptions, do you have more code or the rest of the exception stack trace?
It's throwing an EOFException when attempting to open the file. The initial contents of the file is only an int, specifically '0'. I'm not really sure what to make of it. I tested the code with debug statements and this is definitely the code causing the problem. All other streams to this file are terminated prior to the call to this line.
•
•
Join Date: Sep 2008
Posts: 1,568
Reputation:
Solved Threads: 196
Try opening it with this constructor:
public FileInputStream(File file);
First, create the File Object. See if creating the File object also throws an Exception; if so, print the Exception's contents and getMessage() message in here. Also use the File class's file.canRead() method and tell me if it returns true or false. These are just some thoughts - there's no harm in using a different class to try to find out information about the problem, although this may not yield any answers.
public FileInputStream(File file);
First, create the File Object. See if creating the File object also throws an Exception; if so, print the Exception's contents and getMessage() message in here. Also use the File class's file.canRead() method and tell me if it returns true or false. These are just some thoughts - there's no harm in using a different class to try to find out information about the problem, although this may not yield any answers.
Last edited by BestJewSinceJC; Jun 24th, 2009 at 1:21 am.
Out.
>It's throwing an EOFException when attempting to open the file.
No, that's not true. FileInputStream constructor throws FileNotFoundException.
EOFException signals that an end of file or end of stream has been reached unexpectedly during input.
Post your complete code.
No, that's not true. FileInputStream constructor throws FileNotFoundException.
EOFException signals that an end of file or end of stream has been reached unexpectedly during input.
Post your complete code.
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- how to move a single file from a folder (Java)
- how to download a file without opening file download dialog box (Java)
- urgent (Java)
- HELP please im STUCK! (Java)
- Help with a reservation program! GUI Messed XD (Java)
- Java.io help!!! (Java)
- PLS Help newbie (Java)
- I can't implement a word count into my text editor (JAVA) (Java)
Other Threads in the Java Forum
- Previous Thread: Loading from text file help.
- Next Thread: JOptionPane hide-and-seek
| 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






