Results 1 to 6 of 6
  1. #1
    nat
    nat is offline Member
    Join Date
    Dec 2013
    Posts
    56
    Rep Power
    0

    Default Problem with printing in the output txt file

    Hi,

    I have a for cycle in which I have a line for printing in the output file. But the file remains empty.
    I inserted ShowMessageDialog in the same cycle in order to see what are the results of the calculations that are supposed to appear in the output file, and I see that the results are fine. Can anybody help me please where I make a mistake?

    Here is some of the code:

    XML Code:
     BufferedWriter bwLink = new BufferedWriter(new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_LINK));
                bwLink.close();
    ....
    ....
    ...
      PrintWriter outLink = new PrintWriter(new BufferedWriter(
                                    new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_LINK, true)));
    ...
    ...
    
    JOptionPane.showMessageDialog(GuiMain.this, " Link: " +counter + " Normal: " + trafficResult[0] + " ; " + " Moderate: " + trafficResult[1] + " ; " + " Congested: " + trafficResult[2] + " ; " + " Severe: "+  trafficResult[3], "trafficResult", JOptionPane.INFORMATION_MESSAGE);
    
                               
                                outLink.println("\n" + "Time:" + String.valueOf(sdf.format(now.getTime()))+ " ; " + " Link: " +counter + colorsPercent.getTotal() + " ; " + " Normal: " + trafficResult[0] + " ; " + " Moderate: " + trafficResult[1] + " ; " + " Congested: " + trafficResult[2] + " ; " + " Severe: "+  trafficResult[3]);
    Instead of using the ShowMessageDialog, I want the results to be saved in the output file.
    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Problem with printing in the output txt file

    Do you close the file after writing to it?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    exonaut is offline Member
    Join Date
    Mar 2013
    Posts
    21
    Rep Power
    0

    Default Re: Problem with printing in the output txt file

    Do you have this code:

    Java Code:
    BufferedWriter bwLink = new BufferedWriter(new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_LINK));
                bwLink.close();
    ....
    ....
    ...
      PrintWriter outLink = new PrintWriter(new BufferedWriter(
                                    new FileWriter("." + ToolKit.fileSeparator() + OUTPUT_FILE_LINK, true)));
    in your for loop? If you do then you're constantly making a new file so nothing new is getting output to your text file.

  4. #4
    nat
    nat is offline Member
    Join Date
    Dec 2013
    Posts
    56
    Rep Power
    0

    Default Re: Problem with printing in the output txt file

    Exonaut, no, these codes are out of the for loop.

  5. #5
    nat
    nat is offline Member
    Join Date
    Dec 2013
    Posts
    56
    Rep Power
    0

    Default Re: Problem with printing in the output txt file

    Norm, I don't close the file after writing to it. I have close only after BufferWritter bwlink...
    bwLink.close();

  6. #6
    nat
    nat is offline Member
    Join Date
    Dec 2013
    Posts
    56
    Rep Power
    0

    Default Re: Problem with printing in the output txt file

    Thank you very much Norm, now I put the code for closing the file and it started to work. THANK YOU VERY MUCH!
    Thank you exonaut as well for the try to help me

Similar Threads

  1. Printing selected output only
    By Castle in forum New To Java
    Replies: 1
    Last Post: 11-28-2012, 03:33 PM
  2. Replies: 2
    Last Post: 02-10-2012, 09:50 AM
  3. output jpeg file problem
    By hei1233212000 in forum New To Java
    Replies: 3
    Last Post: 11-29-2010, 11:58 AM
  4. Problem while redirecting script output to a file using java
    By umapathy_sekar in forum Advanced Java
    Replies: 4
    Last Post: 11-09-2010, 09:33 AM
  5. problem with output of jar file
    By nishant.4545 in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2009, 04:00 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •