Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
IO doubt
zarina mohammad
Ranch Hand
Posts: 104
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
why does this IO program produce no output?:
import java.io.*; public class readwrite{ public static void main(String a[]){ try{ FileOutputStream fos=new FileOutputStream("test.txt"); DataOutputStream dos=new DataOutputStream(fos); dos.writeInt(0X012); dos.writeShort(0X11); dos.writeByte(0X02); dos.close(); fos.close(); FileInputStream fis=new FileInputStream("test.txt"); DataInputStream dis=new DataInputStream(fis); int i1= dis.readInt(); int i2= dis.readInt(); System.out.println(("0x"+Integer.toHexString(i1)+", 0x"+Integer.toHexString(i2))); dis.close(); fis.close(); }catch(IOException io){} } }
i was expecting the output to be EOFException.
can someone explain plz.
thanks
zarina
Corey McGlone
Ranch Hand
Posts: 3271
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How can it print EOFException, if you don't put in the code to output the exception? You're catching the exception, so it is considered handled, unlike a runtime exception. If you change your catch block to look like this:
catch(IOException io) { System.out.println("Exception caught: " + io); }
I think you'll see what you're looking for.
Corey
SCJP Tipline, etc.
zarina mohammad
Ranch Hand
Posts: 104
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks for correcting.
Anderson gave himself the promotion. So I gave myself this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to add newline in a textfile using dataouputstream in java
I/O BufferedInputStream
Transfering Files
Read files and replace Strings
Streams Vs Reader/Writer
More...