Chapter Summary
Files that are considered to be strings of characters and that look like characters to your program and to a text editor are called text files. All other files are called binary files.
Your program can use the class
PrintWriter
to write to a text file and can use the classScanner
to read from a text file.When reading from a file, you should always check for the end of a file and do something appropriate if the end of the file is reached. The way you test for the end of a file depends on whether your program is reading from a text file or a binary file.
You can read a file name from the keyboard into a variable of type
String
and use that variable in place of a file name.The class
File
can be used to see whether an existing ...
Get Java: An Introduction to Problem Solving and Programming, 8th Edition 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.