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
Which of the following is true regarding data acquisition? Because data acquisition is often technical, the research team does n
elixir [45]

Answer:

Data acquisition should follow a detailed collection plan that is set in advance.

Explanation:

The process of collection of data over computer with the help of electronic sensors is called data acquisition. The can be related to voltage, current, temperature etc.

For example

Data collection with the help of sensors to monitor weather conditions is an example of data acquisition. In this process data has been gathered on already planned format. Each column or row of data will be helpful to predict the weather condition such as, rain predictions, earthquake prediction etc.

That's why to collect this type of data, collection plan should be set in advance to gather relevant information with the help of data.

4 0
4 years ago
Read 2 more answers
Create an ArrayList of strings to store the names of celebrities and athletes. Add 5 names to the list. Process the list with a
mr Goodwill [35]

Answer:

// ArrayList class is imported

import java.util.ArrayList;

// Iterator class is imported

import java.util.Iterator;

// Main class is defined

class Main {

   // main method to begin program execution

   public static void main(String args[]) {

       // names ArrayList of String is defined

       ArrayList<String> names = new ArrayList<>();

       // 5 names are added to the list

       names.add("John");

       names.add("Jonny");

       names.add("James");

       names.add("Joe");

       names.add("Jolly");

       // for loop to print the names inside the arraylist

       for(int index = 0; index <names.size(); index++){

         System.out.println(names.get(index));

       }

       

       // A blank line is printed

       System.out.println();

       // A newMethod is called with names as argument

       newMethod(names);

       // A blank line is printed

       System.out.println();

       // Instance of Iterator class is created on names

       Iterator<String> iter

           = names.iterator();

 

       // Displaying the names after iterating

       // through the list

       while (iter.hasNext()) {

           System.out.println(iter.next());

       }

   }

   // the newmethod is created here

   public static void newMethod(ArrayList<String> inputArray){

     // A new name is added at index 2

     inputArray.add(2, "Smith");

     // the name in index 4 is removed

     inputArray.remove(4);

     // for each is used to loop the list and print

     for (String name : inputArray) {

       System.out.println(name);

       }

   }

}

Explanation:

The code is well commented. An output image is attached.

7 0
4 years ago
A job placement agency helps match job seekers with potential employers. The agency
padilas [110]

Answer:

The answer is "Option C".

Explanation:

Please find the complete question in the attached file.

The model presented above is an AI design. The specific variable within each AI model becomes reduced. There is also no AI model showing 100% reliability, or just not as reliable as just a man in certain situations. That is why the option C opposes this fact explicitly, and that model is least likely to benefit.

4 0
3 years ago
____ are programs that enable the browser to work with an embedded object.
DerKrebs [107]
HTML's to learn more go to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed
5 0
4 years ago
Although fun and entertainment are the primary functions of video games, they have other uses, as well. An
Zigmanuir [339]

The problem that you think could be addressed by using video games is financial  management skills.

<h3>What problem does gaming handles?</h3>

A lot of Scientific research have seen that video games improve people's creativity and also their skill in terms of problem-solving skills.

Note that it can also help to improve financial management skills and also make people to have stable jobs and good source of income.

Learn more about video games from

brainly.com/question/8870121

6 0
2 years ago
Other questions:
  • The most popular transmission media option for wired home ethernet networks is ________ cable. fiber-optic power-line unshielded
    15·1 answer
  • Which of these jobs would be most appropriate for someone who majors in computer engineering? I need the answer ASAP Helping com
    14·2 answers
  • True or False. Students taking courses log into Blackboard with their "key account" username and password.
    8·1 answer
  • Access Help defaults to searching for information on the _________.<br><br> Not multiple choice
    10·1 answer
  • Technician A says that a lead acid battery uses straight Hydrochloric acid for electrolyte. Technician B says that a lead acid b
    10·2 answers
  • Please help me. i will mark you brailiest
    6·1 answer
  • what are examples of conditional formatting tools? check all that apply. color scales, icon sets,data bars,cell styles,themes
    8·1 answer
  • Which of the following was (and still is) used by computer programmers as a first test program?
    13·2 answers
  • Compare and contrast the uses of NetWitness Investigator and Wireshark used in the lab. Why would a network administrator use Wi
    8·1 answer
  • Javascript and java are really just two slightly different names for the same language.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!