Exam 13: File Input and Output
Exam 1: Creating Your First Java Classes76 Questions
Exam 2: Using Data81 Questions
Exam 3: Using Methods, Classes and Objects79 Questions
Exam 4: More Object Concepts84 Questions
Exam 5: Making Decisions80 Questions
Exam 6: Looping77 Questions
Exam 7: Characters, Strings and the Stringbuilder82 Questions
Exam 8: Arrays77 Questions
Exam 9: Advanced Array Concepts80 Questions
Exam 10: Introduction to Inheritance78 Questions
Exam 11: Advanced Inheritance Concepts78 Questions
Exam 12: Exception Handling79 Questions
Exam 13: File Input and Output78 Questions
Exam 14: Introduction to Swing Components79 Questions
Exam 15: Using Javafx and Scene Builder65 Questions
Select questions type
You can use Java's ____ class to create objects that contain information about files or directories, such as their locations, sizes, creation dates, and whether they even exist.
(Multiple Choice)
4.8/5
(39)
while(nextLine = reader.readLine() != null)
System.out.println(nextLine);
The above loop could be used to read multiple lines from a file. Explain how this loop will execute.
(Essay)
4.7/5
(36)
Explain the difference between an absolute path and a relative path. Provide an example of an absolute path to a file on a system, and then provide an example of a relative path.
(Essay)
4.8/5
(42)
Match each term with the correct statement below.
Premises:
Encompassed
Responses:
close the files
absolute path
volatile storage
Correct Answer:
Premises:
Responses:
(Matching)
4.7/5
(36)
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;
public class PathDemo5
{
public static void main(String[] args)
{
Path myPath = Paths.get("C:\\Java\\Input.Output\\MyData.txt");
try
{
---------Code here ----------
System.out.println("Creation time " + attr.creationTime());
System.out.println("Last modified time " + attr.lastModifiedTime());
System.out.println("Size " + attr.size());
}
catch(IOException e)
{
System.out.println("IO Exception");
}
}
}
Using the above code, create a statement on the indicated line that uses the readAttributes() method of the Files class that takes two arguments-the Path object created in the code and a BasicFileAttributes.class -and returns an instance of the BasicFileAttributes class named attr .
(Essay)
4.8/5
(28)
Some text files are ____ files that contain facts and figures, such as a payroll file that contains employee numbers, names, and salaries.
(Multiple Choice)
4.8/5
(32)
Match each term with the correct statement below.
Premises:
Same as random access files
Responses:
instant access files
BufferedWriter
flushing
Correct Answer:
Premises:
Responses:
(Matching)
4.7/5
(43)
The benefit of using a(n) ____ file is the ability to retrieve a specific record from a file directly, without reading through other records to locate the desired one.
(Multiple Choice)
4.8/5
(40)
____ is an abstract class that contains methods for performing output.
(Multiple Choice)
4.8/5
(34)
Because the backslash character starts the escape sequence in Java, you must use two ____ in a string that describes a Path in the DOS operating system.
(Multiple Choice)
4.9/5
(48)
What tasks are typically performed when working with stored files in an application?
(Essay)
4.8/5
(39)
Match each term with the correct statement below.
Premises:
The main directory of your storage device
Responses:
stream
instant access files
static import feature
Correct Answer:
Premises:
Responses:
(Matching)
4.8/5
(40)
import java.nio.file.*;
import java.io.*;
public class ReadFile
{
public static void main(String[] args)
{
Path file = Paths.get("C:\\Java\\Input.Output\\Grades.txt");
InputStream input = null;
try
{
----Code here-------
----Code here-------
String grade = null;
grade = reader.readLine();
System.out.println(grade);
input.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
} In the code above, a ReadFile class reads from the Grades.txt file. A path is declared, and an InputStream is declared using the Path . In the first indicated line, create the statement to assign a stream to the InputStream reference. In the second indicated line, declare a BufferedReader that reads a line of text from a character-input stream that buffers characters for more efficient reading.
(Essay)
4.8/5
(34)
You can store data in variables within a program, but this type of storage is temporary.
(True/False)
4.8/5
(37)
Match each term with the correct statement below.
Premises:
Operations can start at any specified position
Responses:
buffer
stream
BufferedWriter
Correct Answer:
Premises:
Responses:
(Matching)
4.8/5
(33)
import java.nio.file.*;
import java.io.*;
public class ReadEmployeeFile
{
public static void main(String[] args)
{
Path file =
Paths.get("C:\\Java\\Chapter.13\\Employees.txt");
String s = "";
try
{
InputStream input = new
BufferedInputStream(Files.newInputStream(file));
BufferedReader reader = new
BufferedReader(new InputStreamReader(input));
-----Code here-----
while(s != null)
{
System.out.println(s);
-----Code here-----
}
reader.close();
}
catch(Exception e)
{
System.out.println("Message: " + e);
}
}
}
The above code represents a program that reads an Employees text file. An InputStream is declared for the file, and a BufferedReader is created using the InputStream . On the indicated lines, write a statement that will read the first line into the String . Likewise, in the while statement, write the statement to display the String and read a new line as long as the readLine() method does not return a null value.
(Short Answer)
4.8/5
(37)
import java.nio.file.*;
import java.io.*;
public class ReadEmployeeFile2
{
public static void main(String[] args)
{
Path file =
Paths.get("C:\\Java\\Chapter.13\\Employees.txt");
String[] array = new String[3];
String s = "";
String delimiter = ",";
int id;
String name;
double payRate;
double gross;
final double HRS_IN_WEEK = 40;
double total = 0;
try
{
InputStream input = new
BufferedInputStream(Files.newInputStream(file));
BufferedReader reader = new
BufferedReader(new InputStreamReader(input));
System.out.println();
s = reader.readLine();
while(s != null)
{
-----Code here-----
id = Integer.parseInt(array[0]);
name = array[1];
payRate = Double.parseDouble(array[2]);
gross = payRate * HRS_IN_WEEK;
System.out.println("ID#" + id + " " + name +
" $" + payRate + " $" + gross);
total += gross;
s = reader.readLine();
}
reader.close();
}
catch(Exception e)
{
System.out.println("Message: " + e);
}
System.out.println(" Total gross payroll is $" + total);
}
}
The above code demonstrates a retrieved file where Strings are split into usable fields. On the indicated line, write a String class split() method to split the String s that accepts an argument that identifies the field delimiter (in this example, a comma) and returns an array of Strings . The result should be assigned to the String[] array .
(Short Answer)
4.7/5
(31)
The BufferedWriter class contains a ____ method that uses the current platform's line separator.
(Multiple Choice)
4.9/5
(35)
Match each term with the correct statement below.
Premises:
Functions as a pipeline or channel between a Java program and an input device
Responses:
batch processing
BufferedWriter
close the files
Correct Answer:
Premises:
Responses:
(Matching)
4.8/5
(43)
Showing 21 - 40 of 78
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)