You are on page 1of 2

Documentation

Search
The Java™ Tutorials Hide TOC

Basic I/O
I/O Streams « Previous • Trail • Next » Home Page > Essential Classes > Basic I/O
Byte Streams
Character Streams
The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage
Buffered Streams
of improvements introduced in later releases and might use technology no longer available.
Scanning and
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
Formatting
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for
Scanning
all JDK releases.
Formatting
I/O from the Command
Line I/O Streams
Data Streams
Object Streams An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of
File I/O (Featuring NIO.2) sources and destinations, including disk files, devices, other programs, and memory arrays.
What Is a Path? (And
Streams support many different kinds of data, including simple bytes, primitive data types, localized characters, and
Other File System
objects. Some streams simply pass on data; others manipulate and transform the data in useful ways.
Facts)
The Path Class No matter how they work internally, all streams present the same simple model to programs that use them: A stream
Path Operations is a sequence of data. A program uses an input stream to read data from a source, one item at a time:
File Operations
Checking a File or
Directory
Deleting a File or
Directory
Copying a File or
Directory
Moving a File or
Directory
Managing Metadata
(File and File Store Reading information into a program.
Attributes)
A program uses an output stream to write data to a destination, one item at time:
Reading, Writing, and
Creating Files
Random Access Files
Creating and Reading
Directories
Links, Symbolic or
Otherwise
Walking the File Tree
Finding Files
Watching a Directory for
Changes Writing information from a program.
Other Useful Methods
Legacy File I/O Code In this lesson, we'll see streams that can handle all kinds of data, from primitive values to advanced objects.
Summary
The data source and data destination pictured above can be anything that holds, generates, or consumes data.
Questions and Exercises
Obviously this includes disk files, but a source or destination can also be another program, a peripheral device, a
network socket, or an array.

In the next section, we'll use the most basic kind of streams, byte streams, to demonstrate the common operations of
Stream I/O. For sample input, we'll use the example file xanadu.txt, which contains the following verse:

In Xanadu did Kubla Khan


A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.

« Previous • Trail • Next »

About Oracle | Contact Us | Legal Notices | Terms of Use | Your Privacy Rights

Copyright © 1995, 2021 Oracle and/or its affiliates. All rights reserved.

You might also like