1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nasty-shy [4]
4 years ago
11

Design a class FileArray that has a static method named writeArray. The method should take 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. Write a second static method in the class FileArray named readArray. The method should take two arguments: the name of a file and a reference to an int array. The file should be opened, data should be read from the file and written into the array, and then the file should be closed.
Computers and Technology
1 answer:
soldi70 [24.7K]4 years ago
8 0

Answer:

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

public class FileArray

{

public static void writeArray(String fileName, int[] array) throws IOException

{

 FileOutputStream fstream = new FileOutputStream(fileName);

 DataOutputStream outputFile = new DataOutputStream(fstream);

 

 for(int index = 0; index < array.length; index++)

 {

  outputFile.writeInt(array[index]);

 }

 

 outputFile.close();

}

public static void readArray(String fileName, int[] array) throws IOException

{

 FileInputStream fstream = new FileInputStream(fileName);

 DataInputStream inputFile = new DataInputStream(fstream);

 

 for(int index = 0; index < array.length; index++)

 {

  array[index] = inputFile.readInt();

 }

 inputFile.close();

}

}

Explanation:

The above code has the Class named FileArray and Static method as writeArry. and it takes String fileName, int[] array as arguments.String fileName is for the name of the file and int[] array for the reference to the int array. OutputStream and InputStream are abstract classes used to read byte streams to read and write binary data. Content of the file is written to the file.

Second static method of FileArray is wriiten as readArray and it also takes two arguments similar to static method writeArray. In this data is read from the file and written into array.

You might be interested in
For businesses and organizations under recent compliance laws, data classification standards typically include private, confiden
Mnenie [13.5K]
Answer: True






Explanation:
6 0
3 years ago
Which of the following is an object-oriented language?
faltersainse [42]

Answer:

C++

Explanation:

Significant object-oriented languages include: (list order based on TIOBE index) Java, C++, C#, Python, R, PHP, Visual Basic.NET, JavaScript, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Kotlin, Common Lisp, MATLAB, and Smalltalk.

8 0
3 years ago
Why is audio greyed out on powerpoint ms office 2011?
-BARSIC- [3]
Because its a old type of software and probably wont run on your computer
7 0
3 years ago
Which of the following statements accurately describes the early history of digital recording?
Alchen [17]
I would like to say that it was D. If I am not correct, try asking this in history.
6 0
3 years ago
Develop a c program to display the following input output interphase enter a number 5
aniked [119]

Answer:

int main()

{

int number;

printf("Enter a number: ");

scanf_s("%d", &number, sizeof(number));

for (int i = 1; i <= 2; i++) {

 printf("%d*%d=%d\n", number, i, number * i);

}

}

Explanation:

I used the safe scanf_s() that takes a third parameter to indicate the size of the buffer. In this case it is the size of an integer.

7 0
3 years ago
Other questions:
  • Jake is photographing his pet puppy. He wants to preview the image the camera will capture. What part of the camera that is insi
    6·2 answers
  • Write a program that requires the user to enter two floating-point numbers (num1 and num2) from the keyboard. Multiply them and
    6·1 answer
  • You can use ???? a to test tread wear on your tires
    14·2 answers
  • Samantha plans an investigation in which she will study a population of animals. Which of these answers best describes the focus
    8·1 answer
  • To access WordPad, Jill will click on Start, All Programs, Accessories, and WordPad. To access Notepad, Karl will click on Start
    5·1 answer
  • Ava calls tech support because she is unable to send information that a customer has requested. The tech support person tells he
    6·1 answer
  • What is word processors​
    8·1 answer
  • Which of the following is as result of division of Labour​
    5·1 answer
  • ( BRAINLIEST) <br> Name 2 input devices and 2 output devices on a smart phone.
    12·1 answer
  • What block(s) would most effectively keep a sprite from moving off the screen?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!