Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Only outputting to the Output file once

  1. #1
    Junior Member iCurtisIT's Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    22
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Only outputting to the Output file once

    Hi,

    I'm currently having a problem with my code... I am trying to output to a file numerous transactions that have took place.

    if (userInput == 1)
    					{
    						System.out.println("The current account balance is: £" + accountBalance + "0" + "\n");
    						System.out.println("Please enter the amount you would like to transfer");
    						transferOut = console.nextDouble();
    						while (transferOut > accountBalance)
    						{
    							System.out.println("The maximum amount you can transfer is: £" + accountBalance + "0");
    							System.out.println("Please enter another amount.");
    							transferOut = console.nextDouble();
    						}
    						accountBalance = accountBalance - transferOut;
    						transactionNumber = transactionNumber + 1;
    						System.out.println("The remaining balance in your account is: £" + accountBalance + "0");
    						Date date = new Date();
    						outFile.println("Transaction Number " + transactionNumber + " took place on" + " " + date + " " + "with £" + transferOut + "0" + " being transferred out of the account.");
    						PrintWriter updateBalance = new PrintWriter("shop-account.txt");
    						updateBalance.println(accountBalance);
    						updateBalance.close();	
    						outFile.close();
    					}

    The 'outFile' is the output file described above. Any help/guidance would be greatly appreciated.

    Regards

    iCurtisIT


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: Only outputting to the Output file once

    Where have to stored all those transactions?
    Do you want to write individual transactions to the output file?
    Thanks and regards,
    Sambit Swain

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Only outputting to the Output file once

    If you want to write many transaction in single file by multiple call then open that file in append mode.
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("outfilename", true)));

Similar Threads

  1. Not getting an output file
    By camel-man in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 6th, 2013, 11:42 AM
  2. Replies: 19
    Last Post: March 15th, 2013, 03:11 PM
  3. [SOLVED] File input and file output
    By maple1100 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 26th, 2012, 10:11 PM
  4. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  5. Reading File and Outputting Data
    By ChrisMessersmith in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 13th, 2011, 01:40 PM