Java IO Tutorial

简介: Java Io 1Java IO Tutorial2Java IO Overview3Java IO: Files4Java IO: Pipes5Java IO: Networking6Java IO: Byte & Char Arrays7Java IO: System.


Java Io 

1 Java IO Tutorial
2 Java IO Overview
3 Java IO: Files
4 Java IO: Pipes
5 Java IO: Networking
6 Java IO: Byte & Char Arrays
7 Java IO: System.in, System.out, and System.error
8 Java IO: Streams
9 Java IO: Input Parsing
10 Java IO: Readers and Writers
11 Java IO: Concurrent IO
12 Java IO: Exception Handling
13 Java IO: InputStream
14 Java IO: OutputStream
15 Java IO: FileInputStream
16 Java IO: FileOutputStream
17 Java IO: RandomAccessFile
18 Java IO: File
19 Java IO: PipedInputStream
20 Java IO: PipedOutputStream
21 Java IO: ByteArrayInputStream
22 Java IO: ByteArrayOutputStream
23 Java IO: FilterInputStream
24 Java IO: FilterOutputStream
25 Java IO: BufferedInputStream
26 Java IO: BufferedOutputStream
27 Java IO: PushbackInputStream
28 Java IO: SequenceInputStream
29 Java IO: DataInputStream
30 Java IO: DataOutputStream
31 Java IO: PrintStream
32 Java IO: ObjectInputStream
33 Java IO: ObjectOutputStream
34 Java IO: Serializable
35 Java IO: Reader
36 Java IO: Writer
37 Java IO: InputStreamReader
38 Java IO: OutputStreamWriter
39 Java IO: FileReader
40 Java IO: FileWriter
41 Java IO: PipedReader
42 Java IO: PipedWriter
43 Java IO: CharArrayReader
44 Java IO: CharArrayWriter
45 Java IO: BufferedReader
46 Java IO: BufferedWriter
47 Java IO: FilterReader
48 Java IO: FilterWriter
49 Java IO: PushbackReader
50 Java IO: LineNumberReader
51 Java IO: StreamTokenizer
52 Java IO: PrintWriter
53 Java IO: StringReader
54 Java 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&amp;origin=http%3A%2F%2Ftutorials.jenkov.com&amp;url=http%3A%2F%2Ftutorials.jenkov.com%2Fjava-io%2Findex.html&amp;gsrc=3p&amp;ic=1&amp;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&amp;id=I0_1416445511063&amp;parent=http%3A%2F%2Ftutorials.jenkov.com&amp;pfname=&amp;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&amp;usegapi=1&amp;action=share&amp;height=24&amp;annotation=none&amp;origin=http%3A%2F%2Ftutorials.jenkov.com&amp;url=http%3A%2F%2Ftutorials.jenkov.com%2Fjava-io%2Findex.html&amp;gsrc=3p&amp;ic=1&amp;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&amp;id=I1_1416445511067&amp;parent=http%3A%2F%2Ftutorials.jenkov.com&amp;pfname=&amp;rpctoken=26902609" data-gapiattached="true" style="position: absolute; top: -10000px; width: 450px; margin: 0px; border-style: none;"></iframe>

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.







目录
相关文章
|
1月前
|
存储 Java
【IO面试题 四】、介绍一下Java的序列化与反序列化
Java的序列化与反序列化允许对象通过实现Serializable接口转换成字节序列并存储或传输,之后可以通过ObjectInputStream和ObjectOutputStream的方法将这些字节序列恢复成对象。
|
2月前
|
Java 大数据
解析Java中的NIO与传统IO的区别与应用
解析Java中的NIO与传统IO的区别与应用
|
7天前
|
安全 Java API
【Java面试题汇总】Java基础篇——String+集合+泛型+IO+异常+反射(2023版)
String常量池、String、StringBuffer、Stringbuilder有什么区别、List与Set的区别、ArrayList和LinkedList的区别、HashMap底层原理、ConcurrentHashMap、HashMap和Hashtable的区别、泛型擦除、ABA问题、IO多路复用、BIO、NIO、O、异常处理机制、反射
【Java面试题汇总】Java基础篇——String+集合+泛型+IO+异常+反射(2023版)
|
22小时前
|
Java 大数据 API
Java 流(Stream)、文件(File)和IO的区别
Java中的流(Stream)、文件(File)和输入/输出(I/O)是处理数据的关键概念。`File`类用于基本文件操作,如创建、删除和检查文件;流则提供了数据读写的抽象机制,适用于文件、内存和网络等多种数据源;I/O涵盖更广泛的输入输出操作,包括文件I/O、网络通信等,并支持异常处理和缓冲等功能。实际开发中,这三者常结合使用,以实现高效的数据处理。例如,`File`用于管理文件路径,`Stream`用于读写数据,I/O则处理复杂的输入输出需求。
|
17天前
|
数据采集 Java 数据挖掘
Java IO异常处理:在Web爬虫开发中的实践
Java IO异常处理:在Web爬虫开发中的实践
|
30天前
|
Java 数据处理
Java IO 接口(Input)究竟隐藏着怎样的神秘用法?快来一探究竟,解锁高效编程新境界!
【8月更文挑战第22天】Java的输入输出(IO)操作至关重要,它支持从多种来源读取数据,如文件、网络等。常用输入流包括`FileInputStream`,适用于按字节读取文件;结合`BufferedInputStream`可提升读取效率。此外,通过`Socket`和相关输入流,还能实现网络数据读取。合理选用这些流能有效支持程序的数据处理需求。
25 2
|
1月前
|
XML 存储 JSON
【IO面试题 六】、 除了Java自带的序列化之外,你还了解哪些序列化工具?
除了Java自带的序列化,常见的序列化工具还包括JSON(如jackson、gson、fastjson)、Protobuf、Thrift和Avro,各具特点,适用于不同的应用场景和性能需求。
|
1月前
|
缓存 Java
【IO面试题 一】、介绍一下Java中的IO流
Java中的IO流是对数据输入输出操作的抽象,分为输入流和输出流,字节流和字符流,节点流和处理流,提供了多种类支持不同数据源和操作,如文件流、数组流、管道流、字符串流、缓冲流、转换流、对象流、打印流、推回输入流和数据流等。
【IO面试题 一】、介绍一下Java中的IO流
|
1月前
|
Java
"揭秘Java IO三大模式:BIO、NIO、AIO背后的秘密!为何AIO成为高并发时代的宠儿,你的选择对了吗?"
【8月更文挑战第19天】在Java的IO编程中,BIO、NIO与AIO代表了三种不同的IO处理机制。BIO采用同步阻塞模型,每个连接需单独线程处理,适用于连接少且稳定的场景。NIO引入了非阻塞性质,利用Channel、Buffer与Selector实现多路复用,提升了效率与吞吐量。AIO则是真正的异步IO,在JDK 7中引入,通过回调或Future机制在IO操作完成后通知应用,适合高并发场景。选择合适的模型对构建高效网络应用至关重要。
28 2
|
1月前
|
Java Android开发
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
95 1