Problem

Even though a binary file is not a text file, it can contain embedded text. To find out if...

Even though a binary file is not a text file, it can contain embedded text. To find out if this is the case, write a program that will open a binary file andread it one byte at a time. Display the integer value of each byte as well as the character, if any, that it represents in ASCII.

Technical details: To convert a byte to a character, use the following code:

char[] charArray = Character.toChars(byteValue);

The argument byteValue of the method toChars is an int whose value equals that of the byte read from the file. The character represented by the byte is charArray[0]. Since an integer is four bytes, byteValue can represent four ASCII characters. The method toChars tries to convert each of the four bytes to a character and places them into a char array. We are interested in just the character at index 0. If a byte in the file does not correspond to a character, the method will throw an IllegalArgumentException. If the exception is thrown, display only the byte value and continue on to the next byte.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT