Java Files  «Prev  Next»


Lesson 1

Java File API

Before we plunge into learning about readers and writers, let us take a slight detour from pure input and output (while still remaining in the java.io package) to learn about files.
Dealing with files is an essential prerequisite for being able to use readers and writers. In this module, you will learn how to:
  1. Manipulate files separately from their contents
  2. Find out what files already exist and how to create new ones
  3. Determine information about a file such as its name and size
  4. Use a random access file and how it differs from a sequential access file

You will also learn about directories, how to move around in them, how to switch from one to another, and how to list their contents.
Input Output File IO Methods
Diagram outlining Classic IO in Java



Input Output File IO Methods
To the left of the diagram are the utility methods 1) readAllBytes, 2) readAllLines, and 3) write methods, designed for simple, common cases.

To the right of those are the methods used to iterate over a stream or lines of text, such as
  1. newBufferedReader,
  2. newBufferedWriter,
  3. newInputStream and
  4. newOutputStream.
These methods are interoperable with the java.io package. To the right of those are the methods for dealing with ByteChannels, SeekableByteChannels, and ByteBuffers, such as the newByteChannel method. Finally, on the far right are the methods that use FileChannel for advanced applications needing file locking or memory-mapped I/O.