Exam 13: File Input and Output
Exam 1: Creating Java Programs68 Questions
Exam 2: Using Data74 Questions
Exam 3: Using Methods, Classes, and Objects68 Questions
Exam 4: More Object Concepts67 Questions
Exam 5: Making Decisions70 Questions
Exam 6: Looping72 Questions
Exam 7: Characters, Strings, and the Stringbuilder73 Questions
Exam 8: Arrays74 Questions
Exam 9: Advanced Array Concepts74 Questions
Exam 10: Introduction to Inheritance70 Questions
Exam 11: Advanced Inheritance Concepts70 Questions
Exam 12: Exception Handling65 Questions
Exam 13: File Input and Output74 Questions
Exam 14: Introduction to Swing Components74 Questions
Exam 15: Advanced Gui Topics69 Questions
Exam 16: Graphics74 Questions
Exam 17: Applets, Images, and Sound72 Questions
Select questions type
import java.nio.file.*;
import static java.nio.file.AccessMode.*;
import java.io.IOException;
public class PathDemo3
{
public static void main(String[] args)
{
Path myFile = Paths.get("C: \\Java\\Chapter.13\\Data.txt");
System.out.println("Path is " + myFile.toString());
try
{
_______________________________________________
System.out.println("File can be read and executed");
}
catch(IOException e)
{
System.out.println
("File cannot be used for this application");
}
}
}
Assuming you have declared a path named myFile, create the checkAccess() method in the blank line provided that will verify that the file exists, and checks that the program can read and write to the file.
Free
(Essay)
4.8/5
(35)
Correct Answer:
myFile.getFileSystem().provider().checkAccess(myFile, READ, WRITE);
A(n) ____ is a holding place for bytes that are waiting to be read or written.
Free
(Multiple Choice)
4.8/5
(36)
Correct Answer:
D
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.
Free
(Multiple Choice)
4.8/5
(36)
Correct Answer:
C
The top-level element in a Path's directory structure is located at index 1.
(True/False)
4.7/5
(33)
Describe and provide an example of the differences between real-time applications and interactive programs.
(Essay)
4.8/5
(42)
While System.err and System.out are both directed by default to the monitor command line, System.err is usually reserved for error messages and System.out is reserved for valid output.
(True/False)
4.9/5
(35)
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.9/5
(35)
____ applications require that a record be accessed immediately while a client is waiting.
(Multiple Choice)
4.9/5
(38)
Java's Path class is used to create objects that contain information about files and directories, while the Files class performs operations on files and directories.
(True/False)
4.8/5
(38)
Match each term with the correct statement below.
-To make files no longer available to your application
(Multiple Choice)
4.7/5
(28)
import java.nio.file.*;
public class PathDemo
{
public static void main(String[] args)
{
Path filePath = Paths.get("C: \\Java\\Input.Output\\LessonInfo.txt");
int count = filePath.getNameCount();
System.out.println("Path is " + filePath.toString());
System.out.println("File name is " +
filePath.getFileName());
System.out.println("There are " + count +
" elements in the file path");
for(int x = 0; x < count; ++x)
System.out.println("Element " + x + " is " +
filePath.getName(x));
}
}
The above code demonstrates the creation of a Path and its method. Describe the output that will display when the code is executed.
(Essay)
4.8/5
(37)
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
{
__________________________________________
__________________________________________
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 shaded line, create the statement to assign a stream to the InputStream reference. In the second shaded line, declare a BufferedReader that reads a line of text from a character-input stream that buffers characters for more efficient reading.
(Essay)
4.9/5
(32)
import java.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;
public class WriteFile
{
public static void main(String[] args)
{
Path myFile = Paths.get("C:\\Java\\Input.Output\\myNumbers.txt");
String nums = "12345";
byte[] data = nums.getBytes();
OutputStream output = null;
try
{
_____________________________________
output.write(data)
output.flush();
output.close();
}
catch(Exception badNums)
{
System.out.println("My numbers: " + badNums);
}
}
}
Using the above code, complete the blank line with a statement that will create a writeable file by constructing a BufferedOutputStream object and assigning it to the OutputStream. No output should appear on the monitor, but a file should be created.
(Essay)
4.7/5
(25)
The BufferedWriter class contains a ____ method that uses the current platform's line separator.
(Multiple Choice)
4.9/5
(45)
What tasks are typically performed when working with stored files in an application?
(Essay)
4.9/5
(37)
Comma-separated values (CSV) is a file format strictly used for working with Java and databases.
(True/False)
4.8/5
(28)
How can you assign program output to a file, rather than to the standard output device? Explain how this works. Give an example.
(Essay)
4.9/5
(43)
Match each term with the correct statement below.
-The main directory of your storage device
(Multiple Choice)
5.0/5
(38)
The true 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
(45)
Showing 1 - 20 of 74
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)