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]
3 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]3 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
Which support function under Tech Mahindra is governing data privacy and protection related requirements
Alex Ar [27]

Answer:

Privacy Policy

Explanation:

PRIVACY POLICY is the support function under Tech Mahindra that is governing data privacy and protection-related requirements.

Given that support functions are functions which assist and in a way contribute to the company goal.

Other support functions are human resources, training and development, salaries, IT, auditing, marketing, legal, accounting/credit control, and communications.

The above statement is based on the fact that the Privacy Policy clarifies all the data protection rights, such as the right to object to some of the production processes that TechM may carry out.

7 0
3 years ago
State three differences between a hard drive and a pen drive​
ExtremeBDS [4]

Answer:

A hard drive is what on your computer stores the operating system and all of the files you download. A pen drive (USB DRIVE) is a portable drive used for storing files that you can plug into computers with usb drive ports and transfer that data over to the computer through the USB Drive and you can also copy data onto the USB Drive from a computer and transfer it to other computers.

Explanation:

Computer Technician

7 0
4 years ago
In mathematics, the notation n! represents the factorial of the nonnegative integer n. The factorial of n is the product of all
hram777 [196]

Answer:

The program to this question can be given as:

Program:

factorial=1 #declare a variable.  

number=int(input("Enter a positive integer:")) #input a number.  

while (number>0): #loop  

   factorial= factorial*number # holding value in factorial variable  

   number=number-1  

print('=',factorial) #print value.

Output:

Enter a positive integer:6  

= 720  

Explanation:

The description of the above python program can be given as:

  • In the above program firstly we define a variable that is "factorial". In this variable, we assign a value that is 1 and it is used to calculate the factorial value.  
  • We define a variable "number". The number variable is used to take input from the user.  
  • Then we define a loop in the loop we calculate the factorial and hold the value in the factorial value in the last we print the value.  

4 0
3 years ago
Josh wrote the following e-mail to his co-worker. PLEASE HELP QUWICK
Vedmedyk [2.9K]

Answer:

Answer choice 4

Explanation:

If Josh sends an e-mail to his... co-<em>worker</em>.... wouldn't that be... <em>work</em>place communication?

3 0
3 years ago
Read 2 more answers
Write a program in Java programming language to display or calculate “Hello, Daddy and Mum”
olganol [36]

Answer:

class Simple{

public static void main(String args[]){

System.out.println("Hello Daddy and Mum);

}

}

Explanation:

First, we create a class, then a method and then give the Integrated Data Environment (IDE) the command to give out an output that says Hello, Daddy and Mum”

8 0
2 years ago
Other questions:
  • SP 800-14, Generally Accepted Principles and Practices for Securing Information Technology Systems, provides best practices and
    9·2 answers
  • "a terminal has two input queues." as a user types each character to the terminal, it is collected in the ____ queue.
    5·1 answer
  • You have a folder on your Windows desktop system that you would like to share with members of your development team. Users need
    13·1 answer
  • 11. John wants to share resources and move a large volume of data quickly over the Internet. John should use which of the follow
    14·1 answer
  • Computer piracy occurs when what is violated
    6·1 answer
  • Each professional association has
    7·1 answer
  • PlZZZZZZZ help will give Brainliest
    8·2 answers
  • To extract detailed and comprehensive responses from your client, use the _____ questioning technique.
    5·2 answers
  • Please describe the role of games in modern society!
    5·2 answers
  • Which statement about routers is !!!FALSE!!!
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!