lecture16 - Administrative Issues File Input/Output Lecture...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
File Input/Output Lecture 16 Administrative Issues • Ongoing – Program 3 due tomorrow • Coming soon – Program 4 comes out tomorrow • Requires File I/O concepts from today’s lecture Streams • Streams have a source – Where water is added to the stream • Streams have a sink – Where water leaves the stream • Water flows from the source to the sink Data Streams • A data stream is similar to a natural stream • Data flows from a source to a sink Water Spring Lake Data Source Data Sink Data Stream Water Stream Input/Output Streams • Input Data Streams – Data flows into a program –Examp l e s • Keyboard input • Reading a file from disk • Output Data Streams – Data flows out of a program –Examp l e s • Printing output to the screen • Writing a file to disk • Input/Output is often called “I/O” More on Streams • A stream is a sequence of bytes • You can perform two operations – Read from a stream •F o r s i
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
I/O Streams in Java • Java provides lots of classes to support I/O streams – All part of the java.io package – Must import the classes you intend to use import java.io.*; • The class hierarchy in java.io supports four major classes of streams InputStream OutputStream Reader Writer Input stream of bytes Output stream of bytes Input stream of 16 bit characters Output stream of 16 bit characters Standard I/O Streams • Three streams are contained by default within the System class System.in • Typically used for keyboard input System.out • Typically writes to the screen System.err • Set to same as System.out by default • Could be used to send error messages to a different output destination Standard I/O Streams • We’ve used System.out since the start of class System.out.print(); System.out.println(); • Since program 2, we’ve used the Keyboard class Keyboard uses System.in to read from the keyboard Inside the Keyboard Class • The Keyboard class hides the complicated details of I/O – Declaring and instantiating a standard input stream reader to correctly access Standard.in – Handling of all IOException s thrown during input using try / catch – Tokenizing a string into individual tokens using a StringTokenizer object – Conversion of data to the requested type – Handling problems/exceptions that occur during conversion (i.e. you type a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2009 for the course ASTRONOMY 1000 taught by Professor Kim during the Spring '01 term at Yonsei University.

Page1 / 6

lecture16 - Administrative Issues File Input/Output Lecture...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online