Exam 13: File Input and Output

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

A(n) ____ is a holding place for bytes that are waiting to be read or written.

(Multiple Choice)
4.9/5
(41)

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.7/5
(35)

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             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.9/5
(33)

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.7/5
(41)

If you simply want to display records in order based on their key field, you need to create a random access file.

(True/False)
4.9/5
(48)

When a String is written, placing each record on a new line makes the output file easier to read and interpret. Since not all platforms use '\n' to separate lines, the BufferedWriter class has two alternatives: the newLine() method and the System.getProperty() method. Describe these two methods and how they operate.

(Essay)
4.8/5
(33)

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
(47)

writer.write(names, 0, names.length()); The above code represents a write() method of the BufferedWriter class. Describe the purpose of the method and how it accepts the String characters.

(Essay)
4.8/5
(43)

The BufferedWriter class contains a ____ method that uses the current platform's line separator.

(Multiple Choice)
4.8/5
(41)

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     {       -------------- Code here -------------------       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 on the indicated line that will verify that the file exists, and checks that the program can read and write to the file.

(Short Answer)
4.8/5
(30)

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      {        -----Code here------        output.write(data)        output.flush();        output.close();      }      catch(Exception badNums)      {          System.out.println("My numbers: " + badNums);      }   } } Using the above code, add a statement on the indicated line 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.8/5
(32)

Describe and provide an example of the differences between real-time applications and interactive programs.

(Essay)
4.9/5
(29)

A ____ is a group of characters that has some meaning.

(Multiple Choice)
4.8/5
(43)

Placing a file in the ____ directory of your storage device is equivalent to tossing a loose document into a drawer.

(Multiple Choice)
4.8/5
(38)

The ____ method returns the last Path element in a list of pathnames.

(Multiple Choice)
4.9/5
(43)

The String class ____ method accepts an argument that identifies the field delimiter and returns an array of String s.

(Multiple Choice)
4.7/5
(36)

When you use the BufferedReader class, you must import the ____ package into your program.

(Multiple Choice)
4.9/5
(43)

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
(31)

Provide an example of batch processing.

(Essay)
4.8/5
(36)

A(n) ____ field is the field in a record that makes the record unique from all others.

(Multiple Choice)
4.8/5
(35)
Showing 41 - 60 of 66
close modal

Filters

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