Exam 13: File Input and Output

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

____ is an abstract class used in Java for input and output (IO) operations.

(Multiple Choice)
4.8/5
(32)

import java.nio.file.*; import java.io.*; import java.nio.channels.FileChannel; import java.nio.ByteBuffer; import static java.nio.file.StandardOpenOption.*; import java.util.Scanner; public class CreateEmployeesRandomFile { public static void main(String[] args) { Scanner input = new Scanner(System.in); Path file = Paths.get("C: \\Java\\Chapter.13\\RandomEmployees.txt"); String s = "000, ,00.00" + System.getProperty("line.separator"); final int RECSIZE = s.length(); FileChannel fc = null; String delimiter = ","; String idString; int id; String name; String payRate; final String QUIT = "999"; try { fc = (FileChannel)Files.newByteChannel(file, READ, WRITE); System.out.print("Enter employee ID number >> "); idString = input.nextLine(); while(!(idString.equals(QUIT))) { _____________________________ System.out.print("Enter name for employee #" + id + " >> "); name = input.nextLine(); System.out.print("Enter pay rate >> "); payRate = input.nextLine(); s = idString + delimiter + name + delimiter + payRate + System.getProperty("line.separator"); byte[] data = s.getBytes(); ByteBuffer buffer = ByteBuffer.wrap(data); _____________________________ fc.write(buffer); System.out.print("Enter next ID number or " + QUIT + " to quit >> "); idString = input.nextLine(); } fc.close(); } catch (Exception e) { System.out.println("Error message: " + e); } The above program will accept any number of employee records as user input and write the records to a file in a loop. In the first shaded line, create the statement to accept the employee data value from the keyboard as a String and convert it to an integer using the parseInt() method. In the second shaded line, create the statement to compute the record's desired position by multiplying the ID number value by the record size.

(Essay)
4.7/5
(41)

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

Briefly describe the Path class in Java.

(Essay)
4.8/5
(44)

Briefly describe the ByteBuffer class.

(Essay)
4.8/5
(25)

Provide an example of batch processing.

(Essay)
4.9/5
(34)

After you create a FileSystem object, you can define a Path using the ____ method with it.

(Multiple Choice)
4.8/5
(39)

Java lets you assign a file to a(n) ____ object so that screen output and file output work in exactly the same manner.

(Multiple Choice)
4.9/5
(37)

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

(Multiple Choice)
4.7/5
(45)

A file channel is ____, meaning you can search for a specific file location and operations can start at any specified position.

(Multiple Choice)
4.7/5
(33)

import java.util.Scanner; import java.nio.file.*; public class PathDemo2 { public static void main(String[] args) { String name; Scanner keyboard = new Scanner(System.in); System.out.print("Enter a file name >> "); name = keyboard.nextLine(); Path inputPath = Paths.get(name); __________________ System.out.println("Full path is " + fullPath.toString()); } } Using the above code, complete the shaded line with a statement that creates an absolute path by assigning the file to the current directory.

(Essay)
4.8/5
(32)

InputStream and OutputStream are subclasses of the ____ class.

(Multiple Choice)
4.8/5
(34)

Match each term with the correct statement below. -Involves performing the same tasks with many records

(Multiple Choice)
4.9/5
(30)

A(n) ____________________ object is an avenue for reading and writing a file.

(Short Answer)
4.8/5
(40)
Showing 61 - 74 of 74
close modal

Filters

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