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
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
ADVERTISEMENT