Question: Java!! Display all the names of a given length from names.dat. This file is in binary. Each entry is in the format: name length (integer)

Java!!

Display all the names of a given length from names.dat. This file is in binary. Each entry is in the format: name length (integer) and name (string).

There are no String reading methods for binary files. You'll have to figure out how to use the length value and readChar method to read all the names

I need this required output:

Enter a length 9ENTER Names of length 9 Ki Burgon Nara Huie Dori Hull 3 results

-----

Enter a length 10ENTER Names of length 10 Alwyn Turl Paco Verty 2 results

----

Enter a length 11ENTER Names of length 11 Lindi Ekins Adriana Bru Linet Greep Rich Yakovl Roy Garrard Alex Fillon Inge Adrain 7 results

This is my code so far, but it is not showing this part of the required output

can someone please explain or fix my coding so that is displays this part of the required output !!!

Ki Burgon Nara Huie Dori Hull 3 results

Alwyn Turl Paco Verty 2 results etc.....

import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Names { public static void main(String[] args) { Scanner kb = new Scanner(System.in); System.out.println("Enter a length"); int length = kb.nextInt(); System.out.println("Names of length " + length); ArrayList names = new ArrayList<>(); try { DataInputStream input = new DataInputStream(new FileInputStream("names.dat")); StringBuilder name = new StringBuilder(); boolean go = true; while (go) { int currentLength=0; try { StringBuffer bf = new StringBuffer(); currentLength = (int) input.readByte(); for(int i=0;i                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!