Question

Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the con

java Program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Copy {

    public static void main(String[] args) {
        if (args.length == 2) {
            File file = new File(args[0]);
            try {
                Scanner fin = new Scanner(file);
                PrintWriter pw = new PrintWriter(args[1]);
                while (fin.hasNextLine()) {
                    pw.println(fin.nextLine());
                }
                fin.close();
                pw.close();
            } catch (FileNotFoundException e) {
                System.out.println(file.getAbsolutePath() + " is not found!");
            }
        } else {
            System.out.println("Please provide file names as command line arguments");
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
java Program Write a program called Copy that accepts the names of an input file and...
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