Results 1 to 3 of 3
- 04-12-2010, 08:02 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 59
- Rep Power
- 0
problem with writing new data into file
hello
again I have problem with writing data into file for recursive method
the problem is that this method doesn't write the new content in to file, keeps reading the old content of file it doesn't read the new content
can you tell me what is the problem with writing the new data into file??Java Code:static void Reordering_solution(FileWriter writer_rordering_out,File reordering){ try { /////////////////////////////////////////////////////////////////////// // some commands/////////////////////////////////////////////// // writing into file////////////////////////////////////////////// for (int g = 0; g < test_after_filling_ordering.size(); g++) { writer_rordering_out.write(test_after_filling_ordering.get(g).toString()); writer_rordering_out.write("\r\n");} writer_rordering_out.write("Empty"); writer_rordering_out.write("\r\n"); ///////////////////////////////////////////////////////// // close writing ///////////////////////////////////// writer_rordering_out.close(); ////////////////////////////////////////////// reading data written/////////////////////// ////////////////////////////////////////////// Scanner inFile_77= new Scanner(new FileInputStream(reordering)); BufferedReader reader_reordering_sub = new BufferedReader(new FileReader(reordering)); line_reodering = null; line_reodering = reader_reordering_sub.readLine(); line_reodering=inFile_77.nextLine(); /////////////////////////////////////////////// //some command to get new data////////// /////////////////////////////////////////////// // writing new data into file///////////////// ///////////////////////////////////////////// File re= new File("reordering"); FileWriter writer_rodering_2 = new FileWriter("reordering"); while (inFile_77.hasNextLine()){ line_reodering=inFile_77.nextLine(); System.out.println(" the line is "+ line_reodering); writer_rodering_2.write(line_reodering); writer_rodering_2.write("\r\n");} /////////////////////////////////////////////////////////////// // calling recursive method//////////////////////////// /////////////////////////////////////////////////////////// Reordering_solution(writer_rodering_2 ,re); }
plzzzzzzz I'm waiting for replies
thanks
- 04-12-2010, 08:24 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
you must close the reader before trying to write:
Java Code:reader_reordering_sub.close ();
- 04-13-2010, 02:34 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Read/write to the same file dynamically is not safe at all. Best way is read the content at once and do write process later. But if your file size is too large then it's kind of difficult/problematic. So what you can do is, create a file with the same name in a different folder location and write to content as you did above.
Similar Threads
-
writing to text file problem
By blumdiggity in forum NetworkingReplies: 1Last Post: 02-26-2010, 02:43 PM -
Problem with writing unicode characters in a file
By ze snow in forum New To JavaReplies: 1Last Post: 02-23-2010, 10:47 PM -
Writing to file problem
By PeraPisar in forum Advanced JavaReplies: 12Last Post: 09-16-2009, 11:00 AM -
having problem in writing a text data to an image filr in JDE -Blackberry !!1
By sanmanlan in forum Other IDEsReplies: 0Last Post: 03-05-2009, 06:18 AM -
Problem while writing xml file
By Rajesh Sahu in forum Java ServletReplies: 0Last Post: 12-23-2008, 04:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks