Question: This program is a Text File I/O example problem. This is a pretty beginner class so we havent discussed any major topics. We are using

This program is a Text File I/O example problem. This is a pretty beginner class so we havent discussed any major topics. We are using abstract methods and exception handling to deal with this problem/ arrays and other basic java topics binary object files.I will include an example as reference to how much we have used. Essentially this is an excersie on Text File I/O

Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the output file should also be sorted from smallest to largest with one number on each line.

Your program should obtain both file names from the user. For the original (input) file, create a text file that stores one number per line with several duplicates in sorted order. The output file should be created by your program. When completed, your program should display a count of numbers in the input file, a count of the numbers in the output file, and the number of duplicates.

Submit your class listings, copies of your input and output text files, and a PrintScreen of the console output when your program is run.

Example:

Input File Contents Output File Contents

1 1

3 3

3 60

3 75

60 80

60 100

75 130

75 140

75 985

80 1000

80

100

130

140

985

985

Input from User

985

1000

Sample console dialog:

Enter input file name or full path: numbers.txt

Enter output file name or full path: output.txt

There were 18 numbers input, 10 output, and 8 duplicates.

EXAMPLE OF CODE NOT PART OF THE QUESTION FOR CONTEXT

* Week: Week 5 * Project: Demonstration * Problem Statement: Create a PrintWriter using a relative file location, * then exercise using the print, println, and printf methods. Also * demonstrate the two versions of constructors * * 1. One which uses a String as a file name * 2. One which uses an OutputFileStream to append to the file * * Discussion Points: * * First constructor version just takes a String for file name (deletes existing file) * - Throws FileNotFooundException if it cannot create the file (invalid * file name, can't write to disk, etc.) * * Demonstrate the print(), println(), and printf() methods * * Second constructor version appends to the file created by first version * * Remember to close the PrintWriter when done */ import java.io.PrintWriter ; import java.io.FileNotFoundException ; import java.io.FileOutputStream ; public class PrintWriterDemo { // Constants public static final String FILE_NAME = "demo.txt" ; public static void main(String[] args) { // Use the "String" version of the PrintWriter constructor to // create an output file PrintWriter writer = null ; // Must put inside a try/catch statement try { writer = new PrintWriter(FILE_NAME) ; } catch (FileNotFoundException e) { System.out.println("Couldn't create file " + FILE_NAME) ; System.exit(0) ; } // Demonstrate the use of print() and println() writer.print("print() and println() work just like ") ; writer.println("their versions in System.out. ") ; writer.println() ; // Demonstrate the use of the printf() method writer.printf("%-15s %15s %n", "LEFT-JUSTIFIED", "RIGHT-JUSTIFIED") ; writer.printf("%-15s %15s %n", "--------------", "---------------") ; writer.printf("%-15s %15.2f %n", "Sam Smith", 100.0) ; writer.printf("%-15s %15.2f %n", "Julie Jones", 90000.0) ; writer.println() ; // Flush and close this version writer.close() ; // Now try the version that appends to the existing file (the "true" parameter) try { writer = new PrintWriter(new FileOutputStream(FILE_NAME, true)) ; } catch (FileNotFoundException e) { System.out.println("Couldn't create file " + FILE_NAME) ; System.exit(0) ; } writer.println("This should append to the existing file...") ; writer.close() ; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!