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 5 of 5

Thread: The output file is empty

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The output file is empty

    Hi,

    I have an output file which should contain some total values from calculations, but at the end it is empty.

    Here is my code in the try catch block:

     BufferedWriter bwArea = new BufferedWriter(new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_AREA));
                bwArea.close();

    in the method after that I have:

     PrintWriter outArea = new PrintWriter(new BufferedWriter(
                                    new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_AREA, true)));
     
     Integer total=traffic[0]+traffic[1]+traffic[2]+traffic[3];
                            double greenPercent = ((double)(traffic[0] )) / total*100;
                            double yellowPercent = ((double)(traffic[1]))/total*100;
                            double redPercent = ((double)traffic[2])/total*100;
                            double blackPercent = ((double)traffic[3])/total*100;
     
     
                            outArea.println("Time:" +String.valueOf(sdf.format(now.getTime()))+ " ; " + " Normal " + String.valueOf(greenPercent ) + " % " + " Moderate " + String.valueOf(yellowPercent ) + " % " + " ; " + " Severe " + String.valueOf(redPercent ) + " % " + " ; " + " Unknown " + String.valueOf(redPercent ) + " % ");

    Can anybody help me please why the file is empty, what have I done wrong?

    Thanks
    Last edited by Norm; February 18th, 2014 at 03:00 PM. Reason: Removed =java from ending code tag


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,098
    Thanks
    52
    Thanked 2,284 Times in 2,255 Posts

    Default Re: The output file is empty

    Does the code close the file after writing to it?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: The output file is empty

    Can you provide an SSCCE that demonstrates this behavior? Don't forget the highlight tags.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The output file is empty

    Thanks.The code doesn't write anything inside, and the file is not opening. I open it after the running of the program and the output file is empty, and it is supposed to write the results of the run.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,337
    Thanks
    182
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: The output file is empty

    You haven't addressed the points brought up by Norm or Kevin. Do you close the writer, or at the least flush it? The posted code above does not. I recommend, as Kevin did, to post an SSCCE

Similar Threads

  1. How to read an empty token and display it in the output??
    By tomwill2134 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2013, 08:37 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, 09: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. File Output
    By Nuggets in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: April 3rd, 2012, 08:55 AM

Tags for this Thread