Forums Register Login

Not able to read file immediately after update the file.

+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 769 times.
Similar Threads
PreparedStatement not working properly
save my application
CSV file validating issue
two files text in java
Writing ArrayList to text file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:14:41.