Mark Schuh
Posts: 8
Nickname: shoe2
Registered: Feb, 2003
|
|
Request help with number sort/algor. # 2
|
Posted: Feb 28, 2003 3:25 PM
|
|
WHOOPS: I forgot the code, sorry about that
Greetings,
I am very new to Java.
Below is a program that will copy the data (numbers) of one file to another new file. It requests the name of each file. It works fine. I am now trying to copy over to the new file--only one of each number--in other words I want to eliminate repeated numbers. If my source file consists of these numbers: 1, 5, 7, 7, 8, 9, 9, 9, 22, 34 -9sentinel I only want to copy over the 1, 5, 7, 8, 9, 22, and 34. (The -9 is taken care of)
Can anyone lead me in the right direction on how I can solve this problem to get rid of repeated numbers?
One other question: Are my Exceptions satisfactory or is there a better way to incorporate them?
Any help would be greatly appreciated.
Best Wishes
Mark Schuh
import java.io.*;
class FileCopyMaster { public static void main(String[] args) {
String sourceFile = null; String brandnewFile = null;
try { System.out.println("Enter the file you want to copy"); sourceFile = SavitchIn.readLineWord();
System.out.println("Enter the file you want to copy"); brandnewFile = SavitchIn.readLineWord();
File fileIn = new File(sourceFile); File fileOut = new File(brandnewFile);
FileInputStream streamIn = new FileInputStream(fileIn); FileOutputStream streamOut = new FileOutputStream(fileOut);
int c; while ((c = streamIn.read()) != -1) { streamOut.write(c); }
streamIn.close(); streamOut.close(); } catch (FileNotFoundException e) { System.err.println("FileCopy: " + e); } catch (IOException e) { System.err.println("FileCopy: " + e); } } }
|
|