Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10.4, Problem 22STQ
Program Plan Intro
“ObjectInputStream” stream class:
- The “ObjectInputStream” is used to read a data from the binary files.
- If the user compare methods in “ObjectInputStream” to the “ObjectInputStream” class methods, each output method has a corresponding input method.
- The primitive datatype of the “ObjectInputStream” class, such as “readInt”, “readLong”, “readDouble”, “readFloat”, and “readChar”.
- The “FileInputStream” is an input stream used for reading data from a “File”. It allows to open a file for reading binary string and to establish the connection within it.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose that a binary file contains exactly three numbers written to the file using the method writeDouble of the class ObjectOutputStream. Suppose further that you write a program to read all three numbers using three invocations of the method readDouble of the class ObjectInputStream. If your program invokes readDouble a fourth time, what will happen?
Write a complete program that uses an ifstream object to read integers from a file called numbers.txt, and an ofstream to write into a file called doubles.txtYour program should have a loop that reads five integers from the input file, then writes the doouble of each (x2) into the input file. Write each value in a separate line.Make sure to close both files before your program terminates.
Write a complete program that uses an ifstream object to read integers from a file called numbers.txt, and an ofstream object to write into a file called evens.txt.Your program should have loop that reads each integer from the input file, then writes it into the output file if it is an even number. Write each even number in na separate line.Make sure to close both files before your program terminates.
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 10.1 - Why would anybody write a program that sends its...Ch. 10.1 - When we discuss input, are we referring to data...Ch. 10.1 - What is the difference between a text file and a...Ch. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Prob. 5STQCh. 10.2 - Prob. 6STQCh. 10.2 - Prob. 7STQCh. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Suppose you run a program that writes to the text...Ch. 10.2 - Prob. 10STQ
Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 12PP
Knowledge Booster
Similar questions
- You would use a stream's clear method to: Multiple answers: Multiple answers are accepted for this question a empty the output buffer b reset flags after a failed translation/extraction c clear the screen d clean up after a bad file open attempt e forget an end-of-file encounter before seeking back to the beginning of the streamarrow_forwardWrite a program that removes all the occurrences of a specifiedstring from a text file. For example, invokingjava Exercise12_11 John filenameremoves the string John from the specified file. Your program should get thearguments from the command line.arrow_forwardConsider you are given a data file with the following text: FirstName LastName, 25 You are just interested in reading the FirstName LastName into a string variable named fullname. What will work? Assume all streams have already been defined. Group of answer choices a) fin>>fulllname; b) getline(fin, fullname); c) getline(fin, fullname, ','); Both (b) and (c) All (a), (b) and (c) None of these ------------------------------ Which of the following is/are used to check for the end of file? Group of answer choices .fail() .end() .bad() Both .fail() and .bad() None of the above All of the above =============== Which of the following code segments would result in the number 14.56 being output? Group of answer choices cout << showpoint << setprecision(2) << 14.5555; cout << fixed << showpoint << 14.5555; cout << scientific << setprecision(2) << 14.5555; None of thesearrow_forward
- 1. Create a program that writes an Integer object to a stream and reads this object from the stream. 2. Simple Encryption. Read from a file specified by the user and encrypt the content of the file using a simple shifting technique. Also, ask the user to input the shift size. Output the encrypted message to another file whose filename is also provided by the user. For example, Shift size: 1 Message read from the file: Hello Encrypted message: Ifmmparrow_forwardDoes the class FileOutputStream have a constructor that accepts a filename as an argument?arrow_forwardAssume the size of the file.txt below is 100 GB. Is there anything wrong with the following Spark code? Is there anything wrong with this code? How can it be fixed? from collections import defaultdict text_file = sc.textFile("file.txt") counts = text_file.flatMap(lambda line: line.split(" ")).map(lambda word: (word, 1)).collect() key_val = defaultdict(int) for item in counts: key = item[0] val = item[1] key_val[key] += int(val) filtered_key_val = dict() for k, v in key_val.items(): if v >= 100: filtered_key_val[k] = v return filtered_key_valarrow_forward
- Does the following command to create an input stream and connect to text file named "mydata.dat" work? if not how can you fix it? file inputStream = new file("mydata.dat");arrow_forwardWrite a program that reads every line in a text file, removes the first wordfrom each line, and then writes the resulting lines to a new text file.arrow_forwardWrite a program that reads the-zen-of-python.txt and writes each line to UpdatedZen.txt, a new text file. It capitalizes the first character of each line and adds a period to the end of each line before writing it back to updatedzen.txt. the-zen-of-python.txt file contents: beautiful is better than ugly explicit is better than implicit simple is better than complex complex is better than complicated flat is better than nested sparse is better than dense readability counts special cases aren't special enough to break the rules although practicality beats purity errors should never pass silently unless explicitly silenced in the face of ambiguity, refuse the temptation to guess there should be one-- and preferably only one --obvious way to do it although that way may not be obvious at first unless you're Dutch now is better than never although never is often better than *right* now if the implementation is hard to explain, it's a bad idea if the implementation is easy to explain, it…arrow_forward
- Describe the advantages of using a FileInputStream over a FileReader when dealing with binary data.arrow_forwardWhere do input and output streams diverge? Are there any drawbacks to use the fstream.h file?arrow_forwardWhich is true? a. The FileOutputStream class includes println( ) b. A PrintWriter object should be closed using close( ) c. A PrintWriter constructor requires an OutputStream object d. A FileOutputStream object opens an existing file JAVAarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,