Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to read file immediately after update the file.  RSS feed

 
Gopi Chella
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code i have written, just i am reading content from one file(inputFile) and substitute couple of string then write it into another file(outputFile).

i am not sure whats going wrong in the below code, because as soon as i execute the above method then i am not able to read the updated file(outputFile). I am receiving empty string.

Additional observation, however after update the file if i open the file manually then i am able to read the file programmaticaly. Need help and advice where i am making mistake.


 
K. Tsang
Bartender
Posts: 3630
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you need to make sure the "content" is correct after it is read using commonUtils.

Then the replaceAll stuff with the map thing ... the first parm is the regular expression (your key) ... but the question is "is there a match".

Once replaceAll is done, the content string should still be intact.


From your description, the content after commonUtils is empty because it can't find the file? But then doesn't it have exception?

Honestly not very familiar with commons io api.
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to give more information on what is actually happening. For example when you say:
1. "because as soon as i execute the above method then i am not able to read the updated file(outputFile)" how are you trying to read the updated file?
2. "however after update the file if i open the file manually then i am able to read the file programmaticaly" what do you mean by open the file manually? Have you tried closing and restarting the application and can you read the file then?

Are there any exceptions thrown when you try to read the file after updating it?
You haven't shown the calling code so make sure it isn't catching and discarding any exceptions that might hide the cause of the problem.

BTW when using streams you should always close the stream in a finally clause of a try-catch statement.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!