Chapter 4. Working with Files in Groovy

In this chapter, we will cover:

  • Reading from a file
  • Reading a text file line by line
  • Processing every word in a text file
  • Writing to a file
  • Replacing tabs with spaces in a text file
  • Filtering a text file's content
  • Deleting a file or directory
  • Walking through a directory recursively
  • Searching for files
  • Changing file attributes on Windows
  • Reading data from a ZIP file
  • Reading an Excel file
  • Extracting data from a PDF

Introduction

Groovy offers many shortcuts for dealing with files and directories. Mundane tasks such as listing, copying, renaming, and deleting files are elegantly executed by Groovy, thanks to the methods added to the standard JDK classes such as java.io.File. This chapter's recipes are all about I/O with Groovy, ...

Get Groovy 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.