Owl Teach Yourself Java in 24 Hours, Fifth Edition
HOME / FEEDBACK / ORDER THE BOOK / OTHER BOOKS / PREVIOUS HOUR / NEXT HOUR / THANKS
ROGERS CADENHEAD

Hour 20: Reading and Writing Files

Online Interactive Learning Lab

How to create the Configurator application.

Hour 20 Quiz

Question 1. Which of the following techniques can be used to convert an array of bytes into a string?

1.a. Call the array's toString() method

1.b. Convert each byte to a character, and then assign each one to an element in a String array

1.c. Call the String() constructor method with the array as an argument

You can deal with each byte individually, as suggested in answer b., but you can easily create strings from other data types.

Question 2. What kind of stream is used to read from a file in a Java program?

2.a. An input stream

2.b. An output stream

2.c. Either

An input stream is created from a File object or by providing a filename to the input stream's constructor method.

Question 3. What method of the File class can be used to determine the size of a file?

3.a. getSize()

3.b. read()

3.c. length()

This method returns a long, representing the number of bytes in the stream.

Question 1. When you compile a Java program, what are you doing?

1.a. Saving it to disk

1.b. Converting it into a form the computer can better understand

1.c. Adding it to your program collection

Compiling a program converts a .java file into a .class file or a set of .class files.

Question 2. What is a variable?

2.a. Something that wobbles but doesn't fall down

2.b. Text in a program that the compiler ignores

2.c. A place to store information in a program

Variables are one place to store information; later you learn about others such as arrays and constants. Weebles wobble but they don't fall down, and comments are text in a program that the compiler ignores.

Question 3. What is the process of fixing errors called?

3.a. Defrosting

3.b. Debugging

3.c. Decomposing

Because errors in a computer program are called bugs, fixing those errors is called debugging. Some programming tools come with a tool called a debugger that helps you fix errors.

Notes and Corrections

  • None.

Source Files

Reader Questions

  • None.

Activities

  • Solution 1: IdFiles.java. Before running this application, put one or more MP3 files in the same folder. All of them will be renamed using the ID3 information in the each file, if it exists. Edit
  • Solution 2: JavaReader.java. Edit
   
HOME / FEEDBACK / ORDER THE BOOK / OTHER BOOKS / PREVIOUS HOUR / NEXT HOUR / THANKS

Search terms used to find this page: Java programming, teach yourself, 24 hours, how to, learn, Sams, Macmillan, Java2, JDK1.5, Java 1.5, JDK 1.5, SDK1.5, Java 2 SDK 1.5, SDK 1.5, Java 2 version 1.5, J2SE 1.5, J2SE 5, Java 2 Standard Edition 1.5, Java 2 Standard Edition 5, Java 2 SDK, Java SDK, Rogers Cadenhead, tutorial, hands-on, source code, code, javac, java, appletviewer, help, learning, applet, application, Java Plug-in, plugin, Swing, GUI, interface, Java2D, IO, Java Web Start, games, novice, beginner, neophyte, rookie

Valid HTML 4.01!

Valid CSS!