Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

37.9 Reading and Writing Binary Files In this assignment you will use DataInputStreamand DataOutputStream to read and write a binary file. You will also use

37.9 Reading and Writing Binary Files

In this assignment you will use DataInputStreamand DataOutputStream to read and write a binary file. You will also use FileInputStream and FIleOutputStream to open the file. Step 1) Using DataOutputStream and FileOutputStream, open a file called Binary.dat. Using a Scanner object and FileReader, open the file Input.txt provided. Input.txt consists of of a set of lines, each of which looks this

2.49 24 carrots 

The first number is a price, the second a quantity, and the string is the item.

Step 2) Read each line of Input.txt (use the nextDouble(), nextInt(), and nextLine() methods of the Scanner. Write the values from each line to Binary.dat using the writeDouble(), writeInt(), and writeUTF() methods of the DataOutputStream.

Step 3) Close the DataOutputStream and the Scanner.

Step 4) Open Binary.dat for reading using DataInputStream and FileInputStream. Read each of the triples using readDouble(), readInt(), and readUTF() of the DataInputStream and display the values using System.out.println().

Input.txt

2.49 24 carrots 10.99 100 paper cups 5.49 20 premium saltines 3.69 30 eggs 6.79 15 apples 9.99 20 lunch box 4.49 15 ham sandwich

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions