Results 1 to 3 of 3
  1. #1
    sara12345 is offline Member
    Join Date
    Dec 2009
    Posts
    59
    Rep Power
    0

    Default writing results of recursion into file

    hello
    I have recursive function and I want to write the results of this recursive function into file without deleting the old content of file but the problem I have is that when I call recursive function it overwrites results on the content of file
    this is the code
    Java Code:
    static void Reordering_solution(File reordering){
    	 try {
    	FileWriter writer_rodering_out = new FileWriter(reordering);
    	///////////////////////////////////////////////////
              function
            ////////////////////////////////////////////
          writing into file
        /////////////////////////////////////////////
       Reordering_solution( reordering)
    }
    any suggestion how to fix this problem

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sara12345 View Post
    hello
    I have recursive function and I want to write the results of this recursive function into file without deleting the old content of file but the problem I have is that when I call recursive function it overwrites results on the content of file
    this is the code
    Java Code:
    static void Reordering_solution(File reordering){
    	 try {
    	FileWriter writer_rodering_out = new FileWriter(reordering);
    	///////////////////////////////////////////////////
              function
            ////////////////////////////////////////////
          writing into file
        /////////////////////////////////////////////
       Reordering_solution( reordering)
    }
    any suggestion how to fix this problem
    Don't (re)open the output file every time your recursive method runs but pass it an OutputStream as a parameter. Close the stream outside of that method when it has finished (and open it before you call it for the first time).

    kind regards,

    Jos

  3. #3
    concer is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  2. recursion and tail-recursion differences
    By OptimusPrime in forum New To Java
    Replies: 2
    Last Post: 12-28-2009, 06:26 PM
  3. Replies: 9
    Last Post: 10-20-2009, 10:52 AM
  4. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  5. Replies: 9
    Last Post: 07-10-2008, 04:52 PM

Posting Permissions

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