Question

Write a program in Java which accepts Input from F
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class HelloWorld {

private static final String fname = "input.txt";

public static void main(String[] args) {
        // defining readers to red
  BufferedReader b = null;
  FileReader f = null;

  try {

   f = new FileReader(fname);
   b = new BufferedReader(f);

   String line;

   b = new BufferedReader(new FileReader(fname));

            // reading file line by line
   while ((line = b.readLine()) != null) {
    System.out.println(line);
   }

  }
  // if excepitons is caught, printing the trace
  catch (IOException e) {
   e.printStackTrace();

  } finally {

   try {
       // closing the opened readers
    if (b != null)
     b.close();
    if (f != null)
     f.close();

   }
   // this is for catching the exception.
   catch (IOException ex) {
    ex.printStackTrace();
   }
  }
}
}

Chegg is a good platform to learn Keep up the good work, it will be paid off one day

Add a comment
Know the answer?
Add Answer to:
Write a program in Java which accepts Input from File and provides output on screen.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java Program Write a program called Copy that accepts the names of an input file and...

    java Program Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt

  • java Write a program called Copy that accepts the names of an input file and an...

    java Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt

  • Write a complete java program that accepts input from the user, strips any spaces or punctuation...

    Write a complete java program that accepts input from the user, strips any spaces or punctuation then sorts the characters of the input and outputs the sorted characters. For example, input is "I Love Java!" would output "aaeIJLovv"

  • Write a program in Java that reads the file and does two things: Write to an...

    Write a program in Java that reads the file and does two things: Write to an output file called dataSwitch.txt the same data from the input file, but switch the order of the data entries on each line. For example, if the first line of the input file is “90001 57110”, the first line of the output file would be “57110 90001”. Additionally, print to the screen the number of lines in the file with a label

  • Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following...

    Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following requirement. You and your partner will be writing a simple Java program that implements some basic file I/O operations. You can use this code as the basis for some of your next project. FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each...

  • Need Java help: 1. Create a Java program that accepts input String input from a user...

    Need Java help: 1. Create a Java program that accepts input String input from a user of first name. 2. Create a Java program that accepts input String input from a user of last name. 3. Concatenate the Strings in a full name variable and print to the console.

  • Write a Java program that has a method called arrayAverage that accepts an arrary of numbers...

    Write a Java program that has a method called arrayAverage that accepts an arrary of numbers as an argument and returns the average of the numbers in that array. Create an array to test the code with and call the method from main to print the average to the screen. The array size will be from a user's input (use Scanner). - array size = int - avergage, temperature = double - only method is arrayAverage Output:

  • In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that...

    In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that represents an annual salary for employees. This program should all be written in the main driver program no additional classes are needed. Your program should do the following: Prompt the user for a salary continually until the user enters a sentinel value, a negative number. Keep two running totals the first is the total of all original salaries and the second is a total...

  • FOR JAVA Write a program that takes two command line arguments: an input file and an...

    FOR JAVA Write a program that takes two command line arguments: an input file and an output file. The program should read the input file and replace the last letter of each word with a * character and write the result to the output file. The program should maintain the input file's line separators. The program should catch all possible checked exceptions and display an informative message. Notes: This program can be written in a single main method Remember that...

  • In Java code Write a complete method name convertFile that accepts a File object representing an...

    In Java code Write a complete method name convertFile that accepts a File object representing an input text file and a PrintWriter objects as arguments. The method should read the contents of the input file and change all characters to uppercase and store the results in the output file.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT