Java Reference
In-Depth Information
Chapter 7
Working with Files
In this chapter, we will explain the following:
•
The difference between text files and binary files
•
The difference between internal and external file names
•
How to write a program to compare two text files
try...catch
construct
•
The
•
How to perform input/output with binary files
•
How to work with a binary file of records
•
What are random access files
•
How to create and retrieve records from random access files
•
What are indexed files
•
How to update a random access file using an index
7.1 Input/Output in Java
Java has a comprehensive range of classes for performing input/output. We have used
System.in
and
System.out
for
reading from the standard input and writing to the standard output, respectively.
We have used, for instance, the following to read data from a file,
input.txt
:
Scanner in = new Scanner(new FileReader("input.txt"));
In addition, we have used the following to send output to the file,
output.txt:
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
The files we have worked with have all been
text
files (files of characters). In this chapter, we will see how to work
with
binary
files.
Search WWH ::
Custom Search