Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
naga eswar wrote:Thanks a lot for your reply.
I will do as you say... but is we cant update in the existing file without creating new file because i have to update this line in above 2500 files.
Jeff Verdegan wrote:
naga eswar wrote:Thanks a lot for your reply.
I will do as you say... but is we cant update in the existing file without creating new file because i have to update this line in above 2500 files.
Why would a new file of 2500 lines be a problem?
But no, you can't just update a file in place and push lines further down to insert new ones. File systems don't work that way. If you want to insert in the middle of the file, you have to rewrite everything after where you're inserting. So you have two choices:
1) Use a temp file which replaces the original when you're done. The advantages of this approach are that if a problem occurs along the way, your original hasn't been touched, and that it generally can handle larger files than the second approach, since it relies on disk, not memory, which is usually more plentiful.
2) Read the whole file into memory (or at least everything after the first change), and insert lines where you need them, using a List, then write it back out, replacing the old file (or the part of it after the first insert).
Wendy Gibbons wrote:
Jeff I think he was saying he had 2500 files to change. so couldn't afford to duplicate that many files.
Wendy Gibbons wrote:if he makes a temp file and then replaces the original he only needs to have 2501 at max
(a thing I wouldn't do myself, but then I am a paranoid little thing)
naga eswar wrote:
The problem to create duplicates is memory /space (for 2500 extra files).
naga eswar wrote:ya.. it will take lots of time if i do one by one and also if don't have the word (which I am searching) in a particular file
So i want to keep all these files in one folder.
All files has to update at once if i mention the folder path.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
naga eswar wrote:ya.. it will take lots of time if i do one by one
So i want to keep all these files in one folder.
All files has to update at once if i mention the folder path.
naga eswar wrote:The latest post from my side is thta i replied to "Jeff Verdegan "
naga eswar wrote:ya.. it will take lots of time if i do one by one and also if don't have the word (which I am searching) in a particular file
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Joanne
naga eswar wrote:Can you please elobarate which methods we can use and how.
Joanne
naga eswar wrote:ok Paul...
here my problem is that i have logger method(ex. debug) which we are using in maxmium files of our application.
Due to memory related issues we need to insert condition before the method executes. So i need to insert a sentence "if(isDevelopmentEnabled()" before every log.debug(""); method. So first i need to search the word log.debug and if founds "if(isDevelopmentEnabled()" should insert before that line. we have around 2500 files in my application. So its too difficult to do manually. Thats why I need in program to search and update all files.
naga eswar wrote:I can search the required word in all the files in directory and its sub directiry
Joanne
naga eswar wrote:
@Jeff i am not doing replace. i am trying to insert the condition.
If such editor(I am using Eclipse) is there please let me know.
@Joanne... listing the files in a directory is ok... but my requirement is to edit that each file in that directory...
naga eswar wrote:Thanks a lot for replying guys.
i am working as you said .... I get back with code once i finished.
Campbell Ritchie wrote:Read the API for close() and you find out flush is unnecessary.