Download presentation
Presentation is loading. Please wait.
1
Input and Output in Java
Thursday, Jan 24, 2008 Nancy L. Harris
2
Reference for this topic
1/18/2006 CS239 – Spring
3
Pictorial view of data streams (from the Java tutorial)
1/18/2006 CS239 – Spring
4
What can we read and write?
Bytes – used for binary data, sounds, pictures Characters – used for textual data We will focus on character data 1/18/2006 CS239 – Spring
5
What does a “stream” look like
It is not organized as we are used to looking at a “file”. It is conceptually an infinitely long series of bytes. Some readers deal with those bytes as text characters. And each format item (new lines, tabs, spaces) have a corresponding character representation. 1/18/2006 CS239 – Spring
6
What’s a file? A “file” can be thought of as a named bunch of sequential data. That data can be binary (like executable programs) or it can be textual (like the source files you make with JGrasp). Text files are still binary, but their data can be directly interpreted as characters from the Unicode character set. 1/18/2006 CS239 – Spring
7
Processing a file To read from a file To write to a file Open the file
Read its data Close the file To write to a file Write its data 1/18/2006 CS239 – Spring
8
Making a copy of a file Involves reading from a source and writing to a target. Demo 1/18/2006 CS239 – Spring
9
Some fun things you can do with File
See the java api’s for some techniques for preventing file exceptions. 1/24/2008 CS239 – Spring
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.