ITP 120 - Chapter 4 File Access QUIZ

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

T/F A file must always be opened before using it and closed when the program is finished using it.

True

T/F The do-while loop must be terminated with a semicolon.

True

T/F When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

True

T/F When you open a file with the PrintWriter class, the class can potentially throw an IOException.

True

T/F When you pass the name of a file to the PrintWriter constructor, and the file already exists, it will be erased and a new empty file with the same name will be created.

True

T/F You can use the PrintWriter class to open a file for writing and write data to it.

True

When using the PrintWriter class, which of the following import statements would you write near the top of your program?

import java.io.*;

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

A sentinel value ________ and signals that there are no more values to be entered.

is a special value that cannot be mistaken as a member of the list

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext()) { ... }

Which of the following are pre-test loops?

while, for

Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

T/F The do-while loop is a pre-test loop.

False

T/F When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

False

Which of the following will open a file named MyFile.txt and allow you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

________ is the process of inspecting data given to the program by the user and determining if it is valid.

Input validation

This variable controls the number of times that the loop iterates.

Loop control variable

You can use this method to determine whether a file exists.

The File class's exists method

A loop that repeats a specific number of times is known as a(n):

counter-controlled loop

Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

diskOut.println("Calvin");


संबंधित स्टडी सेट्स

6.6 BONE GROWTH AND DEVELOPMENT DEPEND ON BONE REMODELING, WHICH IS A BALANCE BETWEEN BONE FORMATION AND BONE RESORPTION

View Set

Respiratory Centers of the Brain

View Set

CHAPTER 40 - NURSING CARE OF THE CHILD WITH AN ALTERATION IN GAS EXCHANGE/RESPIRATORY DISORDER

View Set