Question

Write a program that reads a file named input.txt and writes a file that contains the...

Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line and write the file itself.

DO NOT WRITE TO input.txt! That will cost a lot of points. Double check this. There is no sin worse than wiping out the client's input file due to carelessness.

Your class name should be FileCopy.

Your program must work in Eclipse, even if you use a different IDE to develop it. It is best to use Eclipse. I am starting you with a simple Eclipse project to get you ready for more complex projects.

Upload FileCopy.java.

A large part of your grade will be how well you follow these directions.

Homework Answers

Answer #1
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class FileCopy {

    public static void main(String[] args) {
        File file = new File("input.txt");
        try {
            Scanner fin = new Scanner(file);
            System.out.print("Enter output file name: ");
            PrintWriter pw = new PrintWriter("output.txt");
            while (fin.hasNextLine()) {
                pw.println(fin.nextLine());
            }
            System.out.println("file is copied successfully");
            pw.close();
            fin.close();
        } catch (FileNotFoundException e) {
            System.out.println(file.getAbsolutePath() + " is not found!");
        }
    }
}
Know the answer?
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
Similar Questions
java program; Write a brief program that writes your name to a file in text format...
java program; Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
● Write code to read the content of the text file input.txt using JAVA. For each...
● Write code to read the content of the text file input.txt using JAVA. For each line in input.txt, write a new line in the new text file output.txt that computes the answer to some operation on a list of numbers. ● If the input.txt has the following: Min: 1,2,3,5,6 Max: 1,2,3,5,6 Avg: 1,2,3,5,6 Your program should generate output.txt as follows: The min of [1, 2, 3, 5, 6] is 1. The max of [1, 2, 3, 5, 6] is...
Java File I/O Write a brief program that writes your name to a file in text...
Java File I/O Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
Write a brief program in JAVA that writes your name to a file in text format...
Write a brief program in JAVA that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare a variable of type ofstream which is used to output a stream into a file: ofstream output; // output is the name of the variable Prompt the user to input values for the grades of 3 students. Use the output operator (<<) to write the grades into grades.txt: output << grade1 << " " << grade2 << " " << grade3 << endl; You...
Write a program for: In a text file INPUT.TXT integers separated by a space, perhaps in...
Write a program for: In a text file INPUT.TXT integers separated by a space, perhaps in a few lines. In a single file view to create a list of these numbers and find the arithmetic mean of the list elements. The resulting value is recorded in a text file OUTPUT.TXT.
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
I can open the file in the program, but I cannot figure out how to properly...
I can open the file in the program, but I cannot figure out how to properly split the data and assign a grade to the number values in the text file. I keep getting :: ValueError: invalid literal for int() with base 10: 'Roger Jones 75\n' Below are the assignment details: This program processes grades for a small class. It reads an input file named grade_input.txt where each record contains a student’s first name, last name and numeric grade (a...
Write UNIX commands to perform the following tasks. Each task must use exactly one line of...
Write UNIX commands to perform the following tasks. Each task must use exactly one line of command. Unless stated otherwise, all files are assumed to be at your current working directory. a) (10 points) Print your current working directory into a file named file1 b) (10 points) Assume that your current working directory is NOT the same as your home directory. Print all file and subdirectory names of your home directory into a file named file2. c) (15 points) Copy...
(must be in C program) Write a program that reads triplets from an input file, into...
(must be in C program) Write a program that reads triplets from an input file, into a, operator, and b and then computes. The program must warn users if division by zero or an unknown operator. The operator is one of the four standard operators +, -, /, *. a and b are integers. For sample input file: 1 + 5 5 / 0 3 * 2 It must generate output: 1 + 5 = 6 5 / 0 =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • 4. List and describe the THREE (3) necessary conditions for complete similarity between a model and...
    asked 24 minutes ago
  • In C++ Complete the template Integer Average program. // Calculate the average of several integers. #include...
    asked 29 minutes ago
  • A uniform rod is set up so that it can rotate about a perpendicular axis at...
    asked 31 minutes ago
  • To the TwoDArray, add a method called transpose() that generates the transpose of a 2D array...
    asked 52 minutes ago
  • How could your result from GC (retention time, percent area, etc.) be affected by these following...
    asked 1 hour ago
  • QUESTION 17 What are the tasks in Logical Network Design phase? (Select five. ) Design a...
    asked 1 hour ago
  • What is the temperature of N2 gas if the average speed (actually the root-mean-square speed) of...
    asked 1 hour ago
  • Question One: Basic security concepts and terminology                         (2 marks) Computer security is the protection of...
    asked 1 hour ago
  • In program P83.cpp, make the above changes, save the program as ex83.cpp, compile and run the...
    asked 1 hour ago
  • the determination of aspirin in commercial preparations experment explain why the FeCl3-KCl-HCl solution was ased as...
    asked 1 hour ago
  • Describe important events and influences in the life of Wolfgang Amadeus Mozart. What styles, genres, and...
    asked 1 hour ago
  • 3.12 Grade Statistics Write a python module "school.py" that prints school information (first 3 lines of...
    asked 1 hour ago