Exam 13: File Input and Output

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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:
Verified

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:
Verified

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:
Verified

C

The top-level element in a Path's directory structure is located at index 1.

(True/False)
4.7/5
(33)

How can you categorize files by the way they store data?

(Essay)
4.8/5
(35)

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
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)