首页 > 代码库 > Java IO Tutorial

Java IO Tutorial


Java Io 

1Java IO Tutorial
2Java IO Overview
3Java IO: Files
4Java IO: Pipes
5Java IO: Networking
6Java IO: Byte & Char Arrays
7Java IO: System.in, System.out, and System.error
8Java IO: Streams
9Java IO: Input Parsing
10Java IO: Readers and Writers
11Java IO: Concurrent IO
12Java IO: Exception Handling
13Java IO: InputStream
14Java IO: OutputStream
15Java IO: FileInputStream
16Java IO: FileOutputStream
17Java IO: RandomAccessFile
18Java IO: File
19Java IO: PipedInputStream
20Java IO: PipedOutputStream
21Java IO: ByteArrayInputStream
22Java IO: ByteArrayOutputStream
23Java IO: FilterInputStream
24Java IO: FilterOutputStream
25Java IO: BufferedInputStream
26Java IO: BufferedOutputStream
27Java IO: PushbackInputStream
28Java IO: SequenceInputStream
29Java IO: DataInputStream
30Java IO: DataOutputStream
31Java IO: PrintStream
32Java IO: ObjectInputStream
33Java IO: ObjectOutputStream
34Java IO: Serializable
35Java IO: Reader
36Java IO: Writer
37Java IO: InputStreamReader
38Java IO: OutputStreamWriter
39Java IO: FileReader
40Java IO: FileWriter
41Java IO: PipedReader
42Java IO: PipedWriter
43Java IO: CharArrayReader
44Java IO: CharArrayWriter
45Java IO: BufferedReader
46Java IO: BufferedWriter
47Java IO: FilterReader
48Java IO: FilterWriter
49Java IO: PushbackReader
50Java IO: LineNumberReader
51Java IO: StreamTokenizer
52Java IO: PrintWriter
53Java IO: StringReader
54Java IO: StringWriter


Java IO Tutorial

 
By Jakob Jenkov
 Connect with me: 
Rate article:
<iframe frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" tabindex="0" vspace="0" width="100%" id="I0_1416445511063" name="I0_1416445511063" src="https://apis.google.com/se/0/_/+1/fastbutton?usegapi=1&origin=http%3A%2F%2Ftutorials.jenkov.com&url=http%3A%2F%2Ftutorials.jenkov.com%2Fjava-io%2Findex.html&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.0KI2lcOUxJ0.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCPnLWTRWXjQ3yHtGTFSsUVyRcOV5g#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&id=I0_1416445511063&parent=http%3A%2F%2Ftutorials.jenkov.com&pfname=&rpctoken=30215823" data-gapiattached="true" style="position: absolute; top: -10000px; width: 450px; margin: 0px; border-style: none;"></iframe>
Share article:
<iframe frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" tabindex="0" vspace="0" width="100%" id="I1_1416445511067" name="I1_1416445511067" src="https://apis.google.com/se/0/_/+1/sharebutton?plusShare=true&usegapi=1&action=share&height=24&annotation=none&origin=http%3A%2F%2Ftutorials.jenkov.com&url=http%3A%2F%2Ftutorials.jenkov.com%2Fjava-io%2Findex.html&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.0KI2lcOUxJ0.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCPnLWTRWXjQ3yHtGTFSsUVyRcOV5g#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Conload&id=I1_1416445511067&parent=http%3A%2F%2Ftutorials.jenkov.com&pfname=&rpctoken=26902609" data-gapiattached="true" style="position: absolute; top: -10000px; width: 450px; margin: 0px; border-style: none;"></iframe>
Tweet

Java IO is an API that comes with Java which is targeted at reading and writing data (input and output). Most applications need to process some input and produce some output based on that input. For instance, read data from a file or over network, and write to a file or write a response back over the network.

The Java IO API is located in the Java IO package (java.io). If you look at the Java IO classes in the java.iopackage the vast amount of choices can be rather confusing. What is the purpose of all these classes? Which one should you choose for a given task? How do you create your own classes to plugin? etc. The purpose of this tutorial is to try to give you an overview of how all these classes are grouped, and the purpose behind them, so you don‘t have to wonder whether you chose the right class, or whether a class already exists for your purpose.

The Scope of the Java IO (java.io) Package

The java.io package doesn‘t actually address all types of input and output. For instance, input from and output to a GUI or web page is not covered in the Java IO package. Those types of input are covered elsewhere, for instance by the JFC classes in the Swing project, or the Servlet and HTTP packages in the Java Enterprise Edition.

The Java IO package is primarily focused on input and output to files, network streams, internal memory buffers etc. However, the Java IO package does not contain classes to open network sockets which are necessary for network communication. For that purpose you need to use the Java Networking API. Once you have opened a socket (network connection) though, you read and write data to and from it via Java IO‘s InputStream and OutputStream classes.

Java NIO - The Alternative IO API

Java also contains another IO API called Java NIO. It contains classes that does much of the same as the Java IO and Java Networking APIs, but Java NIO can work in non-blocking mode. Non-blocking IO can in some situations give a big performance boost over blocking IO.

More Java IO Tools, Tips etc.

The tutorial trail called Java How To‘s and Utilities also contain a few Java IO utilities - e.g. replacing strings in streams, iterating streams using buffers etc.

The Scope of this Java IO Tutorial

The tutorial starts by giving you a solid overview of how the Java IO APIs work, and how you are supposed to use them. After that the tutorial switches to covering the core classes in the Java IO API.

The coverage of the classes in this tutorial is not just an API listing. It‘s more than just a class listing (you can get that from Sun‘s official Java Doc‘s). Rather each text is a short introduction to the class, its purpose, and a few examples of how to use it. In other words, some of the stuff you don‘t find in Sun‘s official Java Doc‘s.

Java 5 to Java 8

The first version of this Java IO tutorial was written based on Java 5, but the classes work pretty much the same all the way up to Java 8 which is the latest version of Java at the time of writing.






Java IO Tutorial