Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:08:56+00:00 2026-05-31T05:08:56+00:00

I have a problem to write these detail in File. I am trying to

  • 0

I have a problem to write these detail in File.
I am trying to write this detail in file but some how this function create File in specific location but its not writing anything into the file.

public void writeBillToFile(double amount , double billingAmount,double taxAmount,
                                   double discount ,double transactionID , double billingNumber , 
                                   int customerID , String tableNumber ,ArrayList listObject  )
    {
        FileWriter fw=null ;
        BufferedWriter bw =null;
        Date d=new Date();        
        long currentTimestamp=d.getTime();
        try{

            fw = new FileWriter("D:/study/ADVANCE_JAVA/PrOgRaMs/WEB_APPS/00_COS-THE MEGA PROJECT/COS_March_03/GeneratedBill/bill"+currentTimestamp+".txt" , true);        
            bw= new BufferedWriter(fw);

            System.out.println("Date and Time :: "+d.toString() +"\t Bill No :: "+billingNumber+"\t Transaction ID :: "+transactionID+"\n");
            bw.write("Date and Time :: "+d.toString() +" Bill No::"+billingNumber+" Transaction ID::"+transactionID);
            bw.newLine();
            Iterator  iteratorObject= listObject.iterator();
            while(iteratorObject.hasNext())        
            {          
                ItemInSessionModel itemObject = (ItemInSessionModel)iteratorObject.next();
                bw.write(itemObject.getItemName()+"    "+itemObject.getItemQty()+"     "+itemObject.getItemRate()+"     "+(itemObject.getItemRate()*itemObject.getItemQty()));
                bw.newLine();
            }

            bw.write("Total Amount ::"+amount);
            bw.newLine();
            bw.write("Discount     ::"+discount);
            bw.newLine();
            bw.write("TAX          ::"+taxAmount);
            bw.newLine();
            bw.write("Bill Amount  ::"+billingAmount);
            bw.newLine();
            bw.write("Thank You...!");
            System.out.println("Successfully Writen in File...!");
        }catch(Exception e)
        {
            System.out.println("Exception in FILE IO :: "+e);
        }
        finally
        {
            try{
            fw.close();
            bw.close();
            }catch(Exception e){}
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:08:57+00:00Added an answer on May 31, 2026 at 5:08 am

    The mistake in your code is that you have closed the instance of FileWriter before closing the instance of BufferedWriter. It will work if you simply swap position of bw.close() and fw.close();
    Your finally block should look like as follows :

    finally
    {
        try
        {
           bw.close();
           fw.close();
        }
        catch(Exception e)
        {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have a problem to write and read properly a CSV file composed of
I have problem with fancybox. I want to write a function that will run
This is Uday. I have a problem with the write performance with a small
I am trying to write documentation comments however I have a problem. /// <summary>
I'm having a really strange problem. I'm trying to download some file and store.
So, there is problem - I have the order to write web-app on Kohana
I have a problem. I need to trace all read/write operations to the registry
I have one problem, I learn how work with socket and I write programm
Ok, so here's the problem I have to solve. I need to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.