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
____ 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)
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
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)