Book contents
- Frontmatter
- Contents
- Preface
- Acknowledgements
- Part I Introduction to Java
- 1 Introduction
- 2 Language basics
- 3 Classes and objects in Java
- 4 More about objects in Java
- 5 Organizing Java files and other practicalities
- 6 Java graphics
- 7 Graphical User Interfaces
- 8 Threads
- 9 Java input/output
- 10 Java utilities
- 11 Image handling and processing
- 12 More techniques and tips
- Part II Java and the network
- Part III Out of the sandbox
- Appendix 1 Language elements
- Appendix 2 Operators
- Appendix 3 Java floating-point
- Index
- References
9 - Java input/output
Published online by Cambridge University Press: 08 January 2010
- Frontmatter
- Contents
- Preface
- Acknowledgements
- Part I Introduction to Java
- 1 Introduction
- 2 Language basics
- 3 Classes and objects in Java
- 4 More about objects in Java
- 5 Organizing Java files and other practicalities
- 6 Java graphics
- 7 Graphical User Interfaces
- 8 Threads
- 9 Java input/output
- 10 Java utilities
- 11 Image handling and processing
- 12 More techniques and tips
- Part II Java and the network
- Part III Out of the sandbox
- Appendix 1 Language elements
- Appendix 2 Operators
- Appendix 3 Java floating-point
- Index
- References
Summary
Introduction
Java provides a consistent framework for all input/output. That framework centers on the concept of a stream. A stream in Java is a sequential flow of bytes in one direction. There is an output stream that carries text to the console and a corresponding input stream that brings text from the keyboard. Another type of output stream carries data to a file, and a corresponding input stream brings data into a program from a file. There is another output stream that sends data through a network port to another computer on the network while an input stream brings in data through a network port from such a source.
The bulk of Java I/O classes belong to the java.io package. (See pediagram in Figure 9.1.) The class hierarchy builds on the base classes InputStream, OutputStream, Reader, and Writer to provide a wide range of input and output tasks. In addition, this package holds stream classes that wrap a stream to add more capabilities to it. Some I/O classes provide a destination or source, such as a file or an array. Others process the stream in some way such as buffering or filtering the data.
Packages involving I/O include:
java.io – the primary Java I/O classes
java.nio, java.nio.* – a set of five packages new with Java 1.4 based on the concept of channels that represent an open connection to a hardware device, file, or other entity. Channels don't supplant streams but rather work with them to add additional capabilities and enhanced scaling when working with large numbers of connections
[…]
- Type
- Chapter
- Information
- Publisher: Cambridge University PressPrint publication year: 2005