Chapter 17 Flashcards

1
Q

Which method can you use to find out the number of the bytes in a file using InputStream?

		A.
length()
		B.
available()
		C.
size()
		D.
getSize()
A

B.

available()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

To append data to an existing file, use _____________ to construct a FileOutputStream for file out.dat.

		A.
new FileOutputStream("out.dat")
		B.
new FileOutputStream("out.dat", false)
		C.
new FileOutputStream("out.dat", true)
		D.
new FileOutputStream(true, "out.dat")
A
C.
new FileOutputStream("out.dat", true)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the following code do?

FileInputStreamfis=newFileInputStream("test.dat");

	A. It creates a new file named test.dat if it does not exist and opens the file so you can write to it.
	B. It creates a new file named test.dat if it does not exist and opens the file so you can write to it and read from it.
	C. It creates a new file named test.dat regardless of whether it exists or not and opens the file so you can write to it.
	D. It creates a new file named test.dat regardless of whether it exists or not and opens the file so you can write to it and read from it.
	E. It creates a FileInputStream for test.dat if test.dat exists.
A

E.

It creates a FileInputStream for test.dat if test.dat exists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which type of exception occurs when creating a DataInputStream for a nonexistent file?

		A.
FileNotExist
		B.
FileNotExistException
		C.
FileNotFound
		D.
FileNotFoundException
A

D.

FileNotFoundException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat?

	A. DataOutputStream outfile = new DataOutputStream(new File("out.dat"));
	B. DataOutputStream outfile = new DataOutputStream(new FileOutputStream("out.dat"));
	C. DataOutputStream outfile = new DataOutputStream(FileOutputStream("out.dat"));
	D. DataOutputStream outfile = new DataOutputStream("out.dat");
A
B.
DataOutputStream outfile = new DataOutputStream(new FileOutputStream("out.dat"));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

After the following program is finished, how many bytes are written to the file t.dat?

importjava.io.*;
	publicclassTest{
	publicstaticvoidmain(String[] args)throwsIOException {
	DataOutputStream output =newDataOutputStream(
	newFileOutputStream("t.dat"));
	output.writeShort(1234);
	output.writeShort(5678);
	output.close();
	}
	}
		A.
2 bytes.
		B.
4 bytes.
		C.
8 bytes.
		D.
16 bytes.
A

B.

4 bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

After the following program is finished, how many bytes are written to the file t.dat?

importjava.io.*;
	publicclassTest{
	publicstaticvoidmain(String[] args)throwsIOException {
	DataOutputStream output =newDataOutputStream(
	newFileOutputStream("t.dat"));
	output.writeChar('A');
	output.close();
	}
	}
		A.
2 bytes.
		B.
4 bytes.
		C.
8 bytes.
		D.
none of the above.
A

A.

2 bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

After the following program is finished, how many bytes are written to the file t.dat?

importjava.io.*;
	publicclassTest{
	publicstaticvoidmain(String[] args)throwsIOException {
	DataOutputStream output =newDataOutputStream(
	newFileOutputStream("t.dat"));
	output.writeChars("ABCD");
	output.close();
	}
	}
		A.
2 bytes.
		B.
4 bytes.
		C.
8 bytes.
		D.
12 bytes.
		E.
16 bytes.
A

C.

8 bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

After the following program is finished, how many bytes are written to the file t.dat?

importjava.io.*;
	publicclassTest{
	publicstaticvoidmain(String[] args)throwsIOException {
	DataOutputStream output =newDataOutputStream(
	newFileOutputStream("t.dat"));
	output.writeUTFString("ABCD");
	output.close();
	}
	}
		A.
2 bytes.
		B.
4 bytes.
		C.
6 bytes.
		D.
8 bytes.
		E.
10 bytes.
A

C.

6 bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
Which of the following statements is true?
		A.
A static variable is not serialized.
		B.
A transient variable is not serialized.
		C.
An object must be an instance of Serializable for it to be serialized.
		D.
The methods in an object are serialized.
A

C.

An object must be an instance of Serializable for it to be serialized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Which of the following is the legal mode for creating a new RandomAccessFile stream?
		A.
"w"
		B.
'r'
		C.
"rw"
		D.
"rwx"
A

C.

“rw”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens if the file test.dat does not exist when you attempt to compile and run the following code?

importjava.io.*;

classTest{
publicstaticvoidmain(String[] args) {
try{
RandomAccessFile raf =
newRandomAccessFile("test.dat","r");
inti = raf.readInt();
}
catch(IOException ex) {
System.out.println("IO exception");
}
}
}
	A. The program does not compile because raf is not created correctly.
	B. The program does not compile because readInt() is not implemented in RandomAccessFile.
	C. The program compiles, but throws IOException because the file test.dat doesn't exist. The program displays IO exception.
	D. The program compiles and runs fine, but nothing is displayed on the console.
A

C.

The program compiles, but throws IOException because the file test.dat doesn’t exist. The program displays IO exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

With which I/O class can you append or update a file?

		A.
RandomAccessFile()
		B.
OutputStream()
		C.
DataOutputStream()
		D.
None of the above
A

A.

RandomAccessFile()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly