Results 1 to 6 of 6
Thread: problem with store
- 08-21-2009, 05:55 PM #1
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.
- 08-21-2009, 05:58 PM #2
this is the code for the second class
Java 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(); } }
- 08-21-2009, 06:35 PM #3
In CreateTextFile class I can only create a blank file. I can t store the information.
- 08-22-2009, 06:34 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
have you flush the output?
- 08-22-2009, 09:55 AM #5
ok i don t understand what you mean with flush the output, i guess not.
- 08-23-2009, 06:55 PM #6
Similar Threads
-
How to store/retrieve PNG image in/from RMS
By jason-nexFIT-mobileXware in forum CLDC and MIDPReplies: 0Last Post: 09-10-2008, 04:01 AM -
Extract xml to store into db
By palanikumark in forum Advanced JavaReplies: 3Last Post: 06-06-2008, 03:09 PM -
Store retrieve and delete
By on7june in forum New To JavaReplies: 1Last Post: 03-08-2008, 05:57 PM -
store file
By kazitula in forum Java AppletsReplies: 0Last Post: 02-17-2008, 09:45 PM -
I would then store a string...
By susan in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks