跳至正文
KnowledgeCity

高级 Java:输入/输出

探索用于创建、读取和写入文件的Oracle新NIO库,并了解它如何简化您的编程任务
Preview the first lesson free. Get full access to all 3 lessons.
课程:随需点播
高级 提供方 :  Scott Stanlick  3 节课 ·  9m  语言:阿拉伯语, 德语, 英语, 西班牙语, 法语, 葡萄牙语, Chinese 

课程简介

In these lessons you will see how to read and write to and from the file system. The legacy file API is used across many older projects, frameworks and libraries. Despite its age, the legacy API is not deprecated and you can still use it with any of the latest Java versions.

You’ll learn how java.nio.file.Path does everything java.io.File can, and generally in a better way, with the new classes able to support symlinks, proper file attributes, metadata, ACLs and more. When working with files or paths, you will likely be using the java.nio.file.Files class, and we’ll cover many common functions that operate on files and directories. Input and Output encompass a broad swath of sources and we naturally need to deal with character and byte file contents. The NIO library is chock-full of everything we need to accomplish whatever I/O requirements we may face.

Learning Objectives:

• Describe the new NIO library

• Understand how to read and write to the file system

• Explain how to create temporary files

您将学到的内容

  • 描述 Java NIO 库及其文件处理功能
  • 使用 Java I/O 对文件系统进行读写操作
  • 使用 java.nio.file.Path 替代旧版 java.io.File API
  • 使用 java.nio.file.Files 类执行常见的文件和目录操作
  • 处理文件元数据、属性、ACL 及符号链接
  • 使用 NIO 库创建临时文件

关键要点

  • 旧版 java.io.File API 并未被弃用,仍可与最新 Java 版本配合使用。
  • java.nio.file.Path 能完成 java.io.File 的所有功能,且通常表现更优,支持符号链接、文件属性、元数据和 ACL。
  • java.nio.file.Files 类提供了许多用于操作文件和目录的常用功能。
  • 输入与输出涵盖广泛的来源,需要同时处理字符和字节形式的文件内容。
  • 本课程涵盖文件的读取、写入以及文件元数据的使用。

常见问题

本课程涵盖哪些内容?

本课程介绍如何在 Java 中对文件系统进行读写操作,包括 NIO 库、java.nio.file.Path 和 java.nio.file.Files 类、文件元数据以及临时文件的创建。课程章节包括读取、写入和文件元数据。

本课程讲授的是旧版文件 API 还是较新的 NIO 库?

两者均有涉及。课程介绍了旧版文件 API(该 API 仍可使用且未被弃用),同时展示了 java.nio.file.Path 和 NIO 库如何以更优的方式完成相同工作,并支持符号链接、文件属性、元数据和 ACL。

学完本课程后我将掌握哪些技能?

您将掌握文件 I/O、I/O 处理、Java 11、Java 高级成像、Java API 以及 Java 非阻塞 I/O 等方面的技能。

本课程的学习目标是什么?

学习目标包括:描述新的 NIO 库、理解如何对文件系统进行读写操作,以及掌握如何创建临时文件。