文件与IO

所有程序都要处理输入和输出。 这一章将涵盖处理不同类型的文件,包括文本和二进制文件,文件编码和其他相关的内容。 对文件名和目录的操作也会涉及到。

Contents:

  • 读写文本数据
  • 打印输出至文件中
  • 使用其他分隔符或行终止符打印
  • 读写字节数据
  • 文件不存在才能写入
  • 字符串的I/O操作
  • 读写压缩文件
  • 固定大小记录的文件迭代
  • 读取二进制数据到可变缓冲区中
  • 内存映射的二进制文件
  • 文件路径名的操作
  • 测试文件是否存在
  • 获取文件夹中的文件列表
  • 忽略文件名编码
  • 打印不合法的文件名
  • 增加或改变已打开文件的编码
  • 将字节写入文本文件
  • 将文件描述符包装成文件对象
  • 创建临时文件和文件夹
  • 与串行端口的数据通信
  • Checking the Existence of a File
  • Reading and Writing to Files
  • Expanding Tildes in Filenames
  • Creating Temporary Files
  • Storing a File Inside Your Program Text
  • Storing Multiple Files in the DATA Area
  • Writing a Unix-Style Filter Program
  • Modifying a File in Place with a Temporary File
  • Modifying a File in Place with the -i Switch
  • Modifying a File in Place Without a Temporary File
  • Locking a File
  • Flushing Output
  • Doing Non-Blocking I/O
  • Determining the Number of Unread Bytes
  • Reading from Many Filehandles Without Blocking
  • Reading an Entire Line Without Blocking
  • Counting Lines (or Paragraphs or Records) in a File
  • Processing Every Word in a File
  • Reading a File Backward by Line or Paragraph
  • Trailing a Growing File
  • Picking a Random Line from a File
  • Randomizing All Lines
  • Reading a Particular Line in a File
  • Processing Variable-Length Text Fields
  • Removing the Last Line of a File
  • Processing Binary Files
  • Using Random-Access I/O
  • Updating a Random-Access File
  • Reading a String from a Binary File
  • Reading Fixed-Length Records
  • Reading Configuration Files
  • Testing a File for Trustworthiness
  • Reading or Writing Unicode from a Filehandle
  • Comparing the Contents of Two Files
  • Reading and writing JSON files
  • Reading and writing YAML files
  • Getting and Setting Timestamps
  • Deleting a File
  • Copying or Moving a File
  • Recognizing Two Names for the Same File
  • Processing All Files in a Directory
  • Globbing, or Getting a List of Filenames Matching a Pattern
  • Processing All Files in a Directory Recursively
  • Removing a Directory and Its Contents
  • Renaming Files
  • Splitting a Filename into Its Component Parts
  • Working with Symbolic File Permissions Instead of Octal Values

评论