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
Doss [256]
4 years ago
11

Write a program that reads a stream of integers from a file and writes only the positive numbers to a second file. The user shou

ld be prompted to enter the names of both the input file and output file in main(), and then main() should attempt to open both files (providing an error if there is an error during this process). The main() method should then call the process() method to read all the integers from the input file and write only the positive integers to the output file. The process() method takes as arguments a Scanner to read from the input and a PrintWriter to write to the output. You can assume that if you are able to successfully open the input file, then there will only be integers in it.
Computers and Technology
1 answer:
erastova [34]4 years ago
6 0

Answer:

Check the explanation

Explanation:

Code to create the program in the question above:

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.OutputStream;

import java.io.PrintWriter;

import java.util.Scanner;

public class ReadWriteInt

{

    public static void main(String args[]) throws IOException

    {

         Scanner input=new Scanner(System.in);

         System.out.println("Enter the name of the input file:");

         String inputFile=input.next();

         System.out.println("Enter the name of the output file:");

         String outputFile=input.next();

         File fin=new File(inputFile);

         File fout=new File(outputFile);

         //print error, if input file does not exist

         if(!fin.exists())

         {

             System.out.println("Error:Input file does not exist");

             System.exit(0);

         }

         //print error, if output file does not exist

         if(!fout.exists())

         {            

             System.out.println("Error:output file does not exist");

             System.exit(0);

         }

         //input stream to read

         Scanner read=new Scanner(fin);

         OutputStream os=new FileOutputStream(fout);

         //output stream to write

         PrintWriter write=new PrintWriter(os,true);

         //read from input file until there are no numbers

         while(read.hasNextLine())

         {

             String num=read.nextLine();

             //convert the string into number

             int number=Integer.parseInt(num);

             //if the number is positive , write it to out put file

             if(number>=0)

             {

                  write.println(number);

                  System.out.println(number);

             }

         }

         System.out.println("Positive numbers are copied successfully");

    }

}

You might be interested in
An access control system that grants users only those rights necessary for them to perform their work is operating on which secu
solmaris [256]

Answer:

B. Least privilege                

Explanation:

  • The principle of least privilege an important principle in computer security.
  • It limits the access rights for users and only grant them with the rights that are sufficient for them to perform their required task.
  • For example a user is granted privilege to execute a file or manipulate data or use only the resources that are required for them to perform a particular task.
  • This principle can be used only to limit and control access rights to system resources and applications.
  • The least privilege is beneficial as it reduces the risk of unauthorized access.
  • For example a user whose task is data entry and has nothing to do with controlling access or granting access rights to users, will only be allowed to enter data to the DB by the principle of least privilege.
7 0
4 years ago
Expresa tu reflexión sobre la necesidad de un código de etica para la IA (inteligencia artificial) , oponia sobre los bots en la
JulsSmile [24]

Answer:

Ethics in artificial intelligence and robotics are of greater importance today as machine learning or robots are put to use to benefit humans and also ti harm humans.

Explanation:

Ethics in robotics or artificial intelligence in sometimes referred to as "roboethics". It is very necessary in todays time because robots are made to interact with the society, the humans.

This is the key concern for ethics which is based on growing awareness of the requirement to regulate, the  advancements in the field of AI in the near future. The future law or regulations should be on the basis of some of the shared values such as privacy, freedom, security, respect for human dignity, non - military, inclusions, etc. Here, the uncertainty is also being recognized, the uncertainty to know the advancements of AI in the near future. Therefore the regulations and ethical dilemmas should be rethought in the middle.

4 0
3 years ago
Python 3.8.2 detais
olga2289 [7]

Answer:

me dont know

Explanation:

5 0
3 years ago
A technician wants to update the organization's disaster recovery plans. Which of the following will allow network devices to be
Illusion [34]

Answer:B) Archives/backups

Explanation: Archive is the group of records of data that are saved for the future use.These are the historic data that is not currently used in the actual location .

Backup is the the the copy of the group of data that is not in the original form to be used in future. Thus the correct option is option(B).

Updating of the plans by the technician cannot be done through other given options because they don't hold the historic records of the data for the renewing of the plans.

6 0
3 years ago
On the CallCenterReport worksheet, add formulas that will summarize the issues for the department entered in cell B3. In cell B6
grin007 [14]

Answer:

In cell B6, formula =INDEX(INDIRECT($B$3),A6)

CallCenter Worksheet Details:

The image of the CallCenter Report worksheet for reference to the question asked is attached below.

Explanation:

Firtsly, an absolute reference in Excel refers to a reference that is "locked" so that rows and columns won't change when copied. To do this,we put a $ dollar sign ( =A$1,) before the row coordinate to lock only the row.

A relative reference in Excel is a cell address without the $ sign in the row and column coordinates example A1.

Having known what absolute and relative reference are, we wlil write the below formula in cell B6 that will later be copied to cell B9:

: =INDEX(INDIRECT($B$3),A6)

5 0
3 years ago
Other questions:
  • Categories of general purpose application software and examples each​
    13·1 answer
  • What is called photo and video edition?
    8·1 answer
  • Web crawlers or spiders collect information from Web pages in an automated or semi-automated way. Only the text of Web pages is
    10·1 answer
  • Retraining is required at intervals of ___ or less.
    10·1 answer
  • A computer is a multipurpose device that accepts input, processes data, stores data, and produces output, all according to a ser
    9·1 answer
  • Define a new class Fighter that inherits from Spaceship. Add a variable property weapon that defaults to an empty string and a v
    14·1 answer
  • What is the right age to start coding in high school?
    11·1 answer
  • What is Error Code: 232011
    11·2 answers
  • Assume we are using the simple model for floating-point representation as given in this book (the representation uses a 14-bit f
    7·1 answer
  • Which of the following best describes a balanced reaction
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!