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().

import java.io.*; import java.util.*;

public class Main { public static void main(String [] args) { /* Replace this comment with your code */ } }

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

=+1 What would you do if you were the IHR manager?

Answered: 1 week ago