Results 1 to 8 of 8
- 03-03-2012, 11:06 AM #1
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Why am I getting an EOF Exception?
I have a file called Human.java and it has 3 three lines of text with 5 characters each.
Here is my code:
And here is the output:Java Code:public class TestClass { public static void main(String[] args) throws IOException { BufferedInputStream test = new BufferedInputStream(new FileInputStream(new File("c:/Human.java"))); System.out.println(test.read()); System.out.println(test.read()); DataInputStream den = new DataInputStream(test); System.out.println(test.read()); System.out.println(den.readUTF()); } }
What is wrong with my DataInputStream please ?107
111
114
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at myPackage.TestClass.main(TestClass.java:19)
Thank you.
- 03-03-2012, 12:13 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
Re: Why am I getting an EOF Exception?
Don't read both through the FileInputStream and the DataInputStream; only read through the DataInputStream (it wraps the other stream).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-03-2012, 12:15 PM #3
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Why am I getting an EOF Exception?
Oh so it is like open in both streams thats why ?
- 03-03-2012, 12:22 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
Re: Why am I getting an EOF Exception?
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-03-2012, 12:23 PM #5
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Why am I getting an EOF Exception?
Interesting.. I would like to learn the reason in detail. Any sources you can suggest ?
- 03-03-2012, 12:34 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
Re: Why am I getting an EOF Exception?
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-03-2012, 12:35 PM #7
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Why am I getting an EOF Exception?
When you say the documentation, do you mean: java.io (Java Platform SE 6)
- 03-03-2012, 12:52 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
unreported exception java.lang.Exception
By Marisabel in forum New To JavaReplies: 6Last Post: 05-01-2011, 03:21 AM -
unreported exception java.lang.Exception; must be caught or declared to be thrown
By arc_remiel in forum New To JavaReplies: 5Last Post: 02-14-2011, 11:39 PM -
How to throw exception w/RMI from Server->Client w/o "nested exception..." mentioned
By nicoeschpiko in forum Advanced JavaReplies: 1Last Post: 02-06-2011, 05:38 AM -
Exception in thread "main" java.lang Exception In InitializerError
By kenzo2009 in forum New To JavaReplies: 4Last Post: 10-25-2010, 07:42 PM -
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks