Question #63003

write a complete method that reads binary file of strings and return the number of strings that are greater than 20 characters in length

Expert's answer

package com.company;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class SmallBinaryFiles {

private final static String FILE_NAME = "here must be ur path to file";

public static void main(String... aArgs) throws IOException{

System.out.println(reader());
}

private static String reader() throws IOException {

SmallBinaryFiles binary = new SmallBinaryFiles();
byte[] bytes = binary.readSmallBinaryFile(FILE_NAME);

if (bytes.length > 20) {
return "size of file read in: " + bytes.length;
}
return "less than 20";
}

private byte[] readSmallBinaryFile(String aFileName) throws IOException {
Path path = Paths.get(aFileName);
return Files.readAllBytes(path);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS