private static void compareAndWrite() {
if(ra.getAccount()==(acc.getAccount())) {
try {
writer=new Formatter("nuevomaest.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
writer.format("%-16d %.2f%n", ra.getAccount(), acc.combinar(ra));
}
}
I have a program that opens two files and compares the records. If two records have a match, the compareAndWrite() method writes a new file where the matching record is reflected. The problem is that this method is called every time there is a match and all the time it overwrites the new file so that it only reflects one record at the end. My question is: How can I make it not overwrite?
I never used the Formatter class but try the following:
I hope it helps you.