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
IOStreams
Write a Java program that writes five strings to the file 1ab08.txt, and then reads those five
strings back into different variables.
The newer versions of Java have changed how they work with file output streams!
throws an exception of type FileNotFoundException, and
throws an IOException.
FileOutputStream
DataOutputStream.close()
In practice, you won't run into these in the lab. But you do need to call them out when
declaring static void main:
public static void main(String[] args) throws IOException
handles both cases.
Build a csharp application that reads from a file and print out the contents of that file in another files words by words (i.e. one word each line)
Describe scenarios where you might need to wrap an InputStream with other stream types, such as DataInputStream or BufferedInputStream.
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
- Write a code segment that creates an ofstream object named outfile, opens a file named numbers.txt, and associates it with outfile. The code should then use a loop to write the numbers 1 through 100 to the file before closing it.arrow_forwardWhy verify a StreamReader object's EndOfStream property before calling ReadLine?arrow_forwardin java' Variables fStream and dataFS are FileInputStream and Scanner, respectively. String fileName is assigned a file's name read from input. Perform the following tasks: Assign fStream with a FileInputStream that opens the file fileName for reading. Assign dataFS with a Scanner created using fStream. Click here for example Ex: If the input is peach2.txt and: Data in file peach2.txt 4.3 then the output is: 4.3 GroceryDataProcessor.java peach1.txt peach2.txt peach3.txt public class GroceryDataProcessor { publicstaticvoidmain(String[] args) throwsIOException { Scannerscnr=newScanner(System.in); StringfileName; doublepeachWeight; FileInputStreamfStream=null; ScannerdataFS=null; fileName=scnr.next(); /* Your code goes here */ peachWeight=dataFS.nextDouble(); System.out.println(peachWeight); fStream.close(); } }arrow_forward
- in java Variables bananaStream and bananaDataFS are FileOutputStream and PrintWriter, respectively. String bananaDataName is assigned a file's name read from input. Perform the following tasks: Assign bananaStream with a new FileOutputStream that opens bananaDataName for writing. Assign bananaDataFS with a new PrintWriter created using bananaStream. Ex: If the input is note.txt Ina, then note.txt contains: Ina ordered bananas 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public class BananaDataProcessor { publicstaticvoidmain(String[] args) throwsIOException { Scannerscnr=newScanner(System.in); StringbananaDataName; StringbananaPurchase; FileOutputStreambananaStream=null; PrintWriterbananaDataFS=null; bananaDataName=scnr.next(); /* Your code goes here */ bananaPurchase=scnr.next(); bananaDataFS.println(bananaPurchase+" ordered bananas"); bananaDataFS.close(); } }arrow_forwardWrite a program that prompts the user for an input file name, reads all words from the input file, and writes the words to the output file sentences.txt. Start a new line whenever a word ends in a period, question mark, or exclamation mark. Complete the following file: sentences.cpp 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { fstream file; ofstream fout; 8. 9 10 string character; cout > input_file_name; 11 12 13 14 file.open(input_file_name.c_str()); fout.open("sentences.txt"); while(file >> character) { for(int i = 0;iarrow_forwardA myfile.txt has the following lines of text, with each line of text having a new line after it: one two Given the following snippet of code: File output = new File("myfile.txt"); try { Files.writeString(output.toPath(), "three\n", StandardOpenOption StandardOpenOption.APPEND); } catch (IOException ex) { System.out.println("Error: } + ex.getMessage()); What would the myfile.txt contain after the code is run? 7°F Partly sunny Q Searcharrow_forwardThe teacher at a school needs help grading an exam with a number of True/False questions. The students’ IDs and test answers are stored in a file. The first entry of the file contains the answer to the test in the form: TTFTFTTTFTFTFFTTFTTF Every other entry in the file is the student’s ID, followed by a blank, followed by the students’ response. For instance, the entry: ABC54102 T FTFTFTTTFTTFTTF TF The student’s ID is ABC54102, answer to question 1 is True, the answer to question 3 is False. Also, the student did not answer question 2 and question 18. The exam has 20 questions. Here is the grading policy: each correct answer is awarded two points, each wrong answer get -1 point, and no answer gets 0 point. Write a program that processes the test data. The output should be the student’s ID, followed by the answers, followed by the test score (total points), followed by the test grade. Assume the following grade scale will be used: 90%-100%, A; 80%-89.99%, B; 70%-79.99%, C; 60%-69.99%,…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_forwardWrite 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.arrow_forwardTwist this assembly code, but this time a program asks the user to write anything and the written text/string must be saved in the file created in the this code.GIVEN CODE: .model small.stack 60h.data filepath db "UC",0filepath2 db "USC\USCMain",0filepath3 db "USC\USCTalamban",0filepath4 db "USC\USCSouth",0filepath5 db "USC\USCNorth",0;for uc banfilepath6 db "USC\USCSouth\BSECE ",0filepath7 db "USC\USCSouth\BSCPE",0create db "USC\USCSouth\BSCPE\Cruz.doc",0handle dw ?data db "My Name is Cruz, Juan"data_size=$-offset data .codemov ax,@datamov ds,ax mov ah,39hlea dx, filepathint 21h mov ah,39hlea dx, filepath2int 21h mov ah,39hlea dx, filepath3int 21h mov ah,39hlea dx, filepath4int 21h mov ah,39hlea dx, filepath5int 21h mov ah,39hlea dx, filepath6int 21h mov ah,39hlea dx, filepath7int 21h mov ah, 3chmov cx, 0mov dx, offset createmov ah, 3chint 21hmov handle, ax mov bx, handlemov dx, offset datamov cx, data_sizemov ah, 40hint 21h mov ah,4chint 21h endarrow_forwardThe getSelectedFile method of a JFileChooser object returns a File object. What exactly is this File object? A string containing a file name, a disk file, something else?arrow_forwardRead the user's name followed by the user's age from the keyboard (standard input). Then use an ofstream object named outdata to write this information separated by a space into a file called outdata. Declare any variables that you need. Be sure to close the file when you are finished writing data to it.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,