Professional Documents
Culture Documents
PDF Test Bank For Absolute Java 5Th Edition Walter Savitch Online Ebook Full Chapter
PDF Test Bank For Absolute Java 5Th Edition Walter Savitch Online Ebook Full Chapter
http://testbankbell.com/product/solution-manual-for-
absolute-c-5-e-5th-edition-walter-savitch/
http://testbankbell.com/product/solution-manual-for-absolute-
java-6th-edition-savitch/
http://testbankbell.com/product/absolute-c-6th-edition-savitch-
solutions-manual/
http://testbankbell.com/product/solution-manual-for-data-
structures-and-other-objects-using-c-4-e-michael-main-walter-
savitch/
Test Bank For Big Java: Early Objects 5th Edition
http://testbankbell.com/product/test-bank-for-big-java-early-
objects-5th-edition/
http://testbankbell.com/product/test-bank-for-java-programming-
from-problem-analysis-to-program-design-5th-edition/
http://testbankbell.com/product/solution-manual-for-problem-
solving-with-c-10th-edition-savitch/
http://testbankbell.com/product/test-bank-for-american-
government-14th-edition-walter-e-volkomer/
http://testbankbell.com/product/test-bank-for-java-
programming-7th-edition/
Test Bank for Absolute Java, 5th Edition: Walter
Savitch
Chapter 10
File I/O
◼ Multiple Choice
1) An ___________ allows data to flow into your program.
(a) input stream
(b) output stream
(c) file name
(d) all of the above
Answer: A
3) Files whose contents must be handled as sequences of binary digits are called:
(a) text files
(b) ASCII files
(c) binary files
(d) output files
Answer: C
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
5) In Java, when you open a text file you should account for a possible:
(a) FileNotFoundException
(b) FileFullException
(c) FileNotReadyException
(d) all of the above
Answer: A
6) There are two common classes used for reading from a text file. They are:
(a) PrintWriter and BufferedReader
(b) FileInputStream and Scanner
(c) BufferedReader and Scanner
(d) None of the above
Answer: C
7) The scanner class has a series of methods that checks to see if there is any more well-formed input
of the appropriate type. These methods are called __________ methods:
(a) nextToken
(b) hasNext
(c) getNext
(d) testNext
Answer: B
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 10 File I/O 3
10) When the method readLine() tries to read beyond the end of a file, it returns the value of:
(a) 1
(b) -1
(c) null
(d) none of the above
Answer: C
11) A __________ path name gives the path to a file, starting with the directory that the program is in.
(a) relative
(b) descendant
(c) full
(d) complete
Answer: A
12) The stream that is automatically available to your Java code is:
(a) System.out
(b) System.in
(c) System.err
(d) all of the above
Answer: D
13) All of the following are methods of the File class except:
(a) exists()
(b) delete()
(c) getDirectory()
(d) getName()
Answer: C
14) The class ObjectOutputStream contains all of the following methods except:
(a) writeInt()
(b) writeChar()
(c) writeDouble()
(d) println()
Answer: D
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
4 Walter Savitch • Absolute Java 5/e Chapter 10 Test Bank
15) The method __________ from the File class forces a physical write to the file of any data that is
buffered.
(a) close()
(b) flush()
(c) writeUTF()
(d) writeObject()
Answer: B
16) The class ObjectInputStream contains all of the following methods except:
(a) readLine()
(b) readChar()
(c) readObject()
(d) readInt()
Answer: A
17) The read() method of the class RandomAccessFile returns the type:
(a) byte
(b) int
(c) char
(d) double
Answer: B
◼ True/False
1) A stream is an object that allows for the flow of data between your program and some I/O device or
some file.
Answer: True
2) Every input file and every output file used by your program has only one name which is the same
name used by the operating system.
Answer: False
4) When your program is finished writing to a file, it should close the stream connected to that file.
Answer: True
5) Only the classes provided for file output contain a method named close.
Answer: False
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 10 File I/O 5
6) The methods of the scanner class do not behave the same when reading from a text file as they do
when used to read from the keyboard.
Answer: False
7) Using BufferedReader to read integers from a file requires the String input to be parsed to an integer
type.
Answer: True
8) A full path name gives a complete path name, starting from the directory the program is in.
Answer: False
9) The File class contains methods that allow you to check various properties of a file.
Answer: True
10) Binary files store data in the same format that is used by any common text editor.
Answer: False
11) Binary files can be handled more efficiently than text files.
Answer: True
12) The preferred stream classes for processing binary files are ObjectInputStream and
ObjectOutputStream.
Answer: True
◼ Short Answer/Essay
1) Explain the differences between a text file, an ASCII file and a binary file.
Answer: Text files are files that appear to contain sequences of characters when viewed in a text
editor or read by a program. Text files are sometimes also called ASCII files because they contain
data encoded using a scheme known as ASCII coding. Files whose contents must be handled as
sequences of binary digits are called binary files.
2) Write a Java statement to create and open an output stream to a file named autos.txt.
Answer: PrintWriter outputStream = new PrintWriter(new FileOutputStream("autos.txt"));
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
6 Walter Savitch • Absolute Java 5/e Chapter 10 Test Bank
4) Write a Java method that returns a String representing a file name entered by the user. Use the
BufferedReader class to obtain input.
Answer:
InputStreamReader(System.in));
return fileName.trim();
5) Use the output stream to the file autos.txt created above in number 2 to write the line “Mercedes” to
the file.
Answer: outputStream.println("Mercedes");
7) Create try and catch block that opens a file named statistics.txt for output. Writes the integers 24,
55, and 76 to the file, and then closes the file.
Answer:
try
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 10 File I/O 7
FileOutputStream("statistics.txt"));
outputStream.println(24);
outputStream.println(55);
outputStream.println(76);
outputStream.close();
catch(FileNotFoundException e)
System.exit(0);
8) Write a Java statement that creates an output stream to append data to a file named autos.txt.
Answer: PrintWriter outputStream = new PrintWriter(new FileOutputStream("autos.txt", true));
9) Write a Java statement to create an input stream to a file named autos.txt. Use the BufferedReader
class.
Answer: BufferedReader inputStream = new BufferedReader(new FileReader("autos.txt"));
10) Write a complete Java program using a BufferedReader object that opens a file named autos.txt and
displays each line to the screen.
Answer:
import java.io.BufferedReader;
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
8 Walter Savitch • Absolute Java 5/e Chapter 10 Test Bank
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
try
while(line != null)
System.out.println(line);
line = inputStream.readLine();
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 10 File I/O 9
inputStream.close();
catch(FileNotFoundException e)
catch(IOException e)
11) Write a Java statement that creates an output stream to a binary file named statistics.dat.
Answer:
ObjectOutputStream outputStream =
12) Use the output stream created in number 11 above to write the String BBC to the file named
statistics.dat.
Answer: outputStream.writeUTF("BBC");
13) Write a Java statement to create an input stream to the binary file statistics.dat.
Answer:
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
10 Walter Savitch • Absolute Java 5/e Chapter 10 Test Bank
ObjectInputStream inputStream =
14) Write a complete Java program that opens a binary file containing integers and displays the contents
to the screen.
Answer:
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.FileNotFoundException;
try
ObjectInputStream inputStream =
new ObjectInputStream(new
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 10 File I/O 11
FileInputStream("statistics.dat"));
int stat = 0;
try
while(true)
stat = inputStream.readInt();
System.out.println(stat);
catch(EOFException e)
inputStream.close();
catch(FileNotFoundException e)
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
12 Walter Savitch • Absolute Java 5/e Chapter 10 Test Bank
catch(IOException e)
15) Write a Java statement that creates a stream that provides read/write access to the file named
autos.txt.
Answer: RandomAccessFile ioStream = new RandomAccessFile("autos.txt", "rw");
16) Write a Java statement to create an input stream to a file named “statistics.dat”.
Answer: Scanner inputStream = new Scanner(new FileReader("statistics.dat"));
17) Write a complete Java program using a Scanner object that opens a file named autos.txt and displays
each line to the screen.
Answer:
import java.util.*;
import java.io.FileReader;
import java.io.FileNotFoundException;
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 10 File I/O 13
try
while(line != null)
System.out.println(line);
line = inputStream.nextLine();
inputStream.close();
catch(FileNotFoundException e)
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Test Bank for Absolute Java, 5th Edition: Walter Savitch
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Nigger Heaven, the Harlem novel of Carl Van Vechten, also was
much discussed. I met some of Mr. Van Vechten's Negro friends,
who were not seeing him any more because of his book. I felt
flattered that they did not mind seeing me! Yet most of them agreed
that Nigger Heaven was broadly based upon the fact of
contemporary high life in Harlem. Some of them said that Harlemites
should thank their stars that Nigger Heaven had soft-pedaled some
of the actually wilder Harlem scenes. While the conventional Negro
moralists gave the book a hostile reception because of its hectic
bohemianism, the leaders of the Negro intelligentsia showed a
marked liking for it. In comparing it with Home to Harlem, James
Weldon Johnson said that I had shown a contempt for the Negro
bourgeoisie. But I could not be contemptuous of a Negro bourgeoisie
which simply does not exist as a class or a group in America.
Because I made the protagonist of my novel a lusty black worker, it
does not follow that I am unsympathetic to a refined or wealthy
Negro.
My attitude toward Nigger Heaven was quite different from that of its
Negro friends and foes. I was more interested in the implications of
the book. It puzzled me a little that the author, who is generally
regarded as a discoverer and sponsor of promising young Negro
writers, gave Lascar, the ruthless Negro prostitute, the victory over
Byron, the young Negro writer, whom he left, when the novel ends, in
the hands of the police, destined perhaps for the death house in Sing
Sing.
Carl Van Vechten also was in Paris in the summer of 1929. I had
been warned by a white non-admirer of Mr. Van Vechten that I would
not like him because he patronized Negroes in a subtle way, to
which the Harlem élite were blind because they were just learning
sophistication! I thought it would be a new experience to meet a
white who was subtly patronizing to a black; the majority of them
were so naïvely crude about it. But I found Mr. Van Vechten not a bit
patronizing, and quite all right. It was neither his fault nor mine if my
reaction was negative.
One of Mr. Van Vechten's Harlem sheiks introduced us after midnight
at the Café de la Paix. Mr. Van Vechten was a heavy drinker at that
time, but I was not drinking liquor. I had recently suffered from a
cerebral trouble and a specialist had warned me against drinking,
even wine. And when a French doctor forbids wine, one ought to
heed. When we met at that late hour at the celebrated rendezvous of
the world's cosmopolites, Mr. Van Vechten was full and funny. He
said, "What will you take?" I took a soft drink and I could feel that Mr.
Van Vechten was shocked.
I am afraid that as a soft drinker I bored him. The white author and
the black author of books about Harlem could not find much of
anything to make conversation. The market trucks were rolling by
loaded with vegetables for Les Halles, and suddenly Mr. Van
Vechten, pointing to a truck-load of huge carrots, exclaimed, "How I
would like to have all of them!" Perhaps carrots were more
interesting than conversation. But I did not feel in any way carroty. I
don't know whether my looks betrayed any disapproval. Really I
hadn't the slightest objection to Mr. Van Vechten's enthusiasm for the
truck driver's raw carrots, though I prefer carrots en casserole avec
poulet cocotte. But he excused himself to go to the men's room and
never came back. So, after waiting a considerable time, I paid the bill
with some Home to Harlem money and walked in the company of the
early dawn (which is delicious in Paris) back to the Rue Jean-
Jacques Rousseau.
Mr. Van Vechten's sheik friend was very upset. He was a precious,
hesitating sheik and very nervous about that introduction, wondering
if it would take. I said that all was okay. But upon returning to New
York he sent me a message from Mr. Van Vechten. The message
said that Mr. Van Vechten was sorry for not returning, but he was so
high that, after leaving us, he discovered himself running along the
avenue after a truck load of carrots.
Among the Negro intelligentsia in Paris there was an interesting
group of story-tellers, poets and painters. Some had received grants
from foundations to continue work abroad; some were being helped
by private individuals; and all were more or less identified with the
Negro renaissance. It was illuminating to exchange ideas with them.
I was an older man and not regarded as a member of the
renaissance, but more as a forerunner. Indeed, some of them had
aired their resentment of my intrusion from abroad into the
renaissance set-up. They had thought that I had committed literary
suicide because I went to Russia.
For my part I was deeply stirred by the idea of a real Negro
renaissance. The Arabian cultural renaissance and the great
European renaissance had provided some of my most fascinating
reading. The Russian literary renaissance and also the Irish had
absorbed my interest. My idea of a renaissance was one of talented
persons of an ethnic or national group working individually or
collectively in a common purpose and creating things that would be
typical of their group.
I was surprised when I discovered that many of the talented Negroes
regarded their renaissance more as an uplift organization and a
vehicle to accelerate the pace and progress of smart Negro society.
It was interesting to note how sharply at variance their artistic outlook
was from that of the modernistic white groups that took a significant
interest in Negro literature and art. The Negroes were under the
delusion that when a lady from Park Avenue or from Fifth Avenue, or
a titled European, became interested in Negro art and invited Negro
artists to her home, that was a token of Negroes breaking into upper-
class white society. I don't think that it ever occurred to them that
perhaps such white individuals were searching for a social and
artistic significance in Negro art which they could not find in their own
society, and that the radical nature and subject of their interest
operated against the possibility of their introducing Negroes further
than their own particular homes in coveted white society.
Also, among the Negro artists there was much of that Uncle Tom
attitude which works like Satan against the idea of a coherent and
purposeful Negro group. Each one wanted to be the first Negro, the
one Negro, and the only Negro for the whites instead of for their
group. Because an unusual number of them were receiving grants to
do creative work, they actually and naïvely believed that Negro
artists as a group would always be treated differently from white
artists and be protected by powerful white patrons.
Some of them even expressed the opinion that Negro art would
solve the centuries-old social problem of the Negro. That idea was
vaguely hinted by Dr. Locke in his introduction to The New Negro.
Dr. Locke's essay is a remarkable chocolate soufflé of art and
politics, with not an ingredient of information inside.
They were nearly all Harlem-conscious, in a curious synthetic way, it
seemed to me—not because they were aware of Harlem's intrinsic
values as a unique and popular Negro quarter, but apparently
because white folks had discovered black magic there. I understood
more clearly why there had been so much genteel-Negro hostility to
my Home to Harlem and to Langston Hughes's primitive Negro
poems.
I wondered after all whether it would be better for me to return to the
new milieu of Harlem. Much as all my sympathy was with the Negro
group and the idea of a Negro renaissance, I doubted if going back
to Harlem would be an advantage. I had done my best Harlem stuff
when I was abroad, seeing it from a long perspective. I thought it
might be better to leave Harlem to the artists who were on the spot,
to give them their chance to produce something better than Home to
Harlem. I thought that I might as well go back to Africa.
XXVIII
Hail and Farewell to Morocco
I SUPPOSE every man who achieves something worthwhile naturally
attracts some woman. I was interested in Carmina, who had a white
lover. Carmina was a pretty colored lady who had recently deserted
the best circles of Harlem for Paris. I liked Carmina. She had lived
her life a lot, even as I, and neither of us could reproach the other
about the past. But when Louise Bryant saw us together she scolded
me. "That girl is not your type," she said. "Why don't you go on living
as you always did? Why do you have to go around with a female on
your arm, simply because you have written a successful novel?" I
said that perhaps it was nothing more than "male conceit." Louise
Bryant laughed and said, "Take care you don't spoil yourself by doing
the thing that every man thinks he ought to do because of male
conceit."
Louise Bryant and Carmina did not like each other. The three of us
were spending a convivial evening together and, feeling gallant, I
tried to find something to praise in Louise's appearance. She had
been to a hairdresser's that afternoon and her neatly shingled hair
was gleaming black. I said, "Louise, your hair is very nice tonight."
Louise smiled her appreciation. But Carmina said, in a loud whisper,
"Can't you see it's dyed?" A blighting frost descended on the party.
It was a sweet relief to give up for awhile discussing problems of
race and art for an atmosphere of pure sensuality and amorous
intrigue. Carmina also had been fed up with too much race in the
upper circles of Harlem, which was why she had fled to Paris. One
night I was drunk and maudlin in Montparnasse and Louise Bryant
shrieked at me in high intoxicated accents, shaking her forefinger at
me, "Go away and write another book. Go home to Harlem or back
to Africa, but leave Paris. Get a grip on yourself." She looked like the
picture of an old emaciated witch, and her forefinger was like a
broomstick. Perhaps it was her better unconscious self warning me,
for she also could not get a grip on herself and get away from Paris.
I heeded the warning. I started off for Africa. But I lingered a long
time in Spain. The weeks turned into months. From Madrid I went to
Andalusia and visited Cordova and Granada again, then went back
to Barcelona. A French radical friend wrote chidingly about my
preference for Spain, so medieval and religion-ridden. I wrote him
that I expected radical changes in medieval Spain sooner than in
nationalistic France. That was no prophecy. The thing was in the air;
students mentioned it to you on the café terraces; waiters spoke of it
in the pensions and restaurants; chauffeurs spoke of their comrades
murdered in Morocco by King Alfonso; bank clerks said a change
was coming soon, and even guides had something to say. That was
in the winter of 1929-30. I was in Spain early in 1930 when the
dictatorship of Primo de Rivera collapsed. In the spring of 1931 I was
in Spanish Morocco when King Alfonso abdicated, and in Tetuán I
witnessed a wonderful demonstration of amity and fraternity between
the native Moorish and civilian Spanish populations. There in Africa I
hankered after Spain again and indited these three sonnets for
Barcelona:
BARCELONA
1
In Barcelona town they dance the nights
Along the streets. The folk, erecting stands
Upon the people's pavements, come together
From pueblo, barrio, in families,
Lured by the lilting playing of the bands,
Rejoicing in the balmy summer weather,
In spreading rings they weave fine fantasies
Like rare mosaics of many-colored lights.