This program is suppose to merge the two files by taking one element at a time from each, and the third file should contain the numbers from both file from lowest to highest.
Data1: 11 25 36 45 56 78 90
Data2: 1 3 5 7 54 32 78 99
Then the third data should output:
data3: 1 3 5 7 11 25 32 36 45 54 56 ..... so on (from low to high)
The program compiles but when I run it, it gives me this error..... how do i fix this, so that it outputs.
> java MergeFiles
Static Error: No static method in MergeFiles with name 'main' accepts arguments (String[])
>
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;
public class MergeFiles {
public static void MergeFiles (String[] args) {
try {
FileReader file1=new FileReader("File1.txt");
Scanner scan = new Scanner(new File("File1.txt"));
ArrayList<Integer> values = new ArrayList<Integer>();
Collections.sort(values); //sorting the values
while(scan.hasNextInt()) values.add(scan.nextInt());
FileReader file2=new FileReader("File2.txt");
scan = new Scanner(new File("File2.txt"));
values = new ArrayList<Integer>();
Collections.sort(values); //sorting the values.
while(scan.hasNextInt()) values.add(scan.nextInt());
BufferedReader br1 = new BufferedReader (file1);
BufferedReader br2 = new BufferedReader(file2);
String temp1 = "";
String temp2 = "";
while(br1.readLine() !=null)
{
temp1=br1.readLine()+temp1;
}
while(br2.readLine()!=null)
{
temp2=br2.readLine()+temp2;
}
String temp = temp1 + temp2;
// Merging the numbers from low to high into a third file.
FileWriter fw=new FileWriter("File3.txt");
char buffer[]=new char[temp.length()];
temp.getChars(0,temp.length(),buffer,0);
fw.write(buffer);
file1.close();
file2.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}