Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.Write a Java program to track how many times the program has been executed. You will store the number (integer) representing the count into a

1.Write a Java program to track how many times the program has been executed. You will store the number (integer) representing the count into a file (count.dat). If the count.dat doesnt exist (e.g., first time to run the program), store 1 in the newly created file. You will use binary IO (FileInputStream / FileOutputSteam) for your code. For this question, you will also need to declare the checked exceptions in the methods header to handle errors. Since the counter.dat file is a binary file (you cannot read it with your typical text editor(eg MS words), you can use your Hex viewer method program from the following question to open the file to examine the contents. If you are using notepad++, you can also download the HexEditor plugin to enable the Hex view

2.

Write a Hex Viewer method with the following header to read a binary file.

private static void viewHex(String filename)

This method reads bytes from the file (data.dat, and your counter.dat from the previous question) and displays them in hex representation. The output should be formatted as shown in the example below. Each line consists of 8 pairs of hex numbers, then |, then another 8 pairs. Use Integer.toHexString( ) to convert a byte into a string representing the equivalent hex. Use try statement to handle IOException and display a simple error message if an I/O exception occurs.

image text in transcribed

Sample run (for the attached data.dat file 00 21 4A 6F 68 6E 20 75 73 65 64 20 74 6F 20 70 6C 61 79 20 66 6F 72 20 74 68 65 20 42 65 61 74 6C 65 73 40 55 60 ee ee e0 0e 00 eE 50 61 75 6C 20 70 6C 61 79 20 62 61 73 65 40 67 30 00 00 00 00 00 06 47 65 6F | 72 67 65 40 5A 50 0 00 00 00 00 01 02 3 04 5 6 7 08 09 0A 0B 0C 0D 0E eF 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 | 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 | 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 4546 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D SE 5F 60 61 62 63 64 63 | (need data.dat file)

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

Ehs 2.0 Revolutionizing The Future Of Safety With Digital Technology

Authors: Tony Mudd

1st Edition

B0CN69B3HW, 979-8867463663

More Books

Students also viewed these Databases questions