Java使用手册-Basic I/O 封面
本文引用来自 Oracle官网 Java 教程,译文属于个人理解。
Lesson: Basic I/O
This lesson covers the Java platform classes used for basic I/O. It first focuses on I/O Streams, a powerful concept that greatly simplifies I/O operations. The lesson also looks at serialization, which lets a program write whole objects out to streams and read them back again. Then the lesson looks at file I/O and file system operations, including random access files.
Most of the classes covered in the
I/O Streams
section are in thejava.io
package. Most of the classes covered in theFile I/O
section are in thejava.nio.file
package.
译:本课讲了用于 basic I/O 的 java 平台类。它首先讲了 I/O Streams,这是个强大的概念,极大地简化了 I/O 操作。本节内容还讨论了序列化的内容,它能让程序把整个对象写入流中,并且读取回来。然后说了 File I/O 和文件系统操作,包括随机访问文件。
I/O 流一节的内容大多存在于 java.io 包里。文件 I/O 一节的类大多存在于 java.nio.file 包里。
I/O Streams
- Byte Streams handle I/O of raw binary data.
- Character Streams handle I/O of character data, automatically handling translation to and from the local character set.
- Buffered Streams optimize input and output by reducing the number of calls to the native API.
- Scanning and Formatting allows a program to read and write formatted text.
- I/O from the Command Line describes the Standard Streams and the Console object.
- Data Streams handle binary I/O of primitive data type and
String
values.- Object Streams handle binary I/O of objects.
译:
I/O Streams
- 字符流:处理二进制数据的I/O。
- 字节流:处理字节数据的I/O,自动处理与本地字符集之间的转换。
- 缓冲流:通过减少对本地API的调用次数优化输入和输出操作。
- 扫描和格式化:允许程序读取和写入格式化的文本。
- 命令行中的I/O:描述标准流和控制器对象。
- 数据流:处理基本数据类型和字符串值的二进制 I/O
- 对象流:处理对象的二进制 I/O
File I/O (Featuring NIO.2)
- What is a Path? examines the concept of a path on a file system.
- The Path Class introduces the cornerstone class of the
java.nio.file
package.- Path Operations looks at methods in the
Path
class that deal with syntactic operations.- File Operations introduces concepts common to many of the file I/O methods.
- Checking a File or Directory shows how to check a file's existence and its level of accessibility.
- Deleting a File or Directory.
- Copying a File or Directory.
- Moving a File or Directory.
- Managing Metadata explains how to read and set file attributes.
- Reading, Writing and Creating Files shows the stream and channel methods for reading and writing files.
- Random Access Files shows how to read or write files in a non-sequentially manner.
- Creating and Reading Directories covers API specific to directories, such as how to list a directory's contents.
- Links, Symbolic or Otherwise covers issues specific to symbolic and hard links.
- Walking the File Tree demonstrates how to recursively visit each file and directory in a file tree.
- Finding Files shows how to search for files using pattern matching.
- Watching a Directory for Changes shows how to use the watch service to detect files that are added, removed or updated in one or more directories.
- Other Useful Methods covers important API that didn't fit elsewhere in the lesson.
- Legacy File I/O Code shows how to leverage
Path
functionality if you have older code using thejava.io.File
class. A table mappingjava.io.File
API tojava.nio.file
API is provided.
译:
File I/O(以 NIO.2 为特征)
- 什么是 Path?研究文件系统上路径的概念。
- Path 类:引入 java.nio.file 的基本类。
- Path 操作:介绍 Path 类中处理语法操作的方法。
- 文件操作:引入很多文件 I/O 方法的通用概念。
- 检查文件或目录:显示怎么检查一个文件的存在和它的可访问级别。
- 删除文件或目录。
- 复制文件或目录。
- 移动文件或目录。
- 管理元数据:解释了怎么读取和设置文件属性。
- 读、写、创建文件:显示了流和通道读写文件的方法。
- 随机访问文件:展示了怎么以非顺序的方式读写文件
- 创建和读取目录:涵盖了特定于目录的API,比如如何列出目录的内容。
- 链接、符号或其他:涵盖了特定的符号和硬链接。
- 遍历文件树:演示如何递归地访问文件树中的每个目录和文件。
- 查找文件:显示如何使用模式匹配来搜索文件。
- 监视目录更改:显示如何使用监视服务来检测在一个或多个目录中添加、删除或更新的文件。
- 其他有用的方法:涵盖了本课程其他部分不适合的重要API。
- 遗留的 File I/O 代码:显示如果有使用了 java.io.File 类的旧代码,如何利用路径功能。提供了一个从 java.io.File API 到 java.nio.file API的映射表。