need to write a FileArray class that has a static method writeArray that takes t
ID: 3638761 • Letter: N
Question
need to write a FileArray class that has a static method writeArray that takes two arguments, the name of a file and a reference to an int array. The file should be opened as a binary file, the contents of the array should be written to the file, and then the file should be closed.A second method, readArray, also take 2 arguments the name of a file and a reference to an int array. File should be opened, data should be read from the file and stored in the array, and then the file should be closed. Demonstrate both methods in a program.
Explanation / Answer
Please rate: Program: import java.io.*; import java.util.Scanner; public class FileArray { private static void pt(String s) { System.out.print(s); } public static void WriteArray(int[] num, String fn) throws IOException { //Create the binary output objects. FileOutputStream fstream = new FileOutputStream(fn); DataOutputStream outputFile = new DataOutputStream(fstream); pt("Writing the numbers to " + fn + "..."); // Write the array elements to the file. for (int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.