-
problem with store
Hello everybody. I ve got problem to a programme which store informations for bank clients. My programme has two classes the first is accountRecord for the information and second CreateTextFile which stores the variables in file. I use a while loop as i want to store a lot of objects. When i put the information for the first client and press enter the compiler does not continue.
-
this is the code for the second class
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package account;
import java.io.FileNotFoundException;
import java.lang.SecurityException;
import java.util.Formatter;
import java.util.FormatterClosedException;
import java.util.NoSuchElementException;
import java.util.Scanner;
/**
*
* @author George
*/
public class CreateTextFile {
private Formatter output;
public void openfile(){
try{
output=new Formatter("clients.txt");
}
catch(SecurityException SecurityException){
System.err.println("YOU DO NOT HAVE THE ACCESS TO THIS FILE.");
System.exit(1);
}
catch(FileNotFoundException filesNotFoundException){
System.err.println("Error creating file.");
System.exit(1);
}
}
public void addRecords(){
AccountRecord record=new AccountRecord();
Scanner input=new Scanner(System.in);
System.out.printf("%s\n%s\n%s\n%s\n",
"To terminate input, type the end-of-file indicator",
"when you are prompted to enter input",
"...",
"........................");
System.out.printf("%s\n%s", "enter account number(>0),first,lastname, and balance","?");
while(input.hasNext()){
try{
record.setAccount(input.nextInt());
record.setfirstName(input.next());
record.setlastName(input.next());
record.setBalance(input.nextDouble());
if(record.getAccount()>0){
output.format("%d %s %s %.2f\n", record.getAccount(),
record.getfirstName(),record.getlastName(),record.getBalance());
}
else{
System.out.println("Account must be greater than 0:");
}
}
catch(FormatterClosedException formatterClosedException){
System.err.println("Error writing to file.");
return;
}
catch(NoSuchElementException elementException){
System.err.println("Invalid input. Please try again.");
input.nextLine();
System.out.printf("%s\n%s", "enter account number(>0),first,lastname, and balance","?");
}
}
}
public void closeFile(){
if(output !=null)
output.close();
}
public static void main(String [] args){
CreateTextFile application=new CreateTextFile();
application.openfile();
application.addRecords();
application.closeFile();
}
}
-
In CreateTextFile class I can only create a blank file. I can t store the information.
-
have you flush the output?
-
ok i don t understand what you mean with flush the output, i guess not.
-
Someone plizz to help with this??