Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Not able to read file immediately after update the file.

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic