As far as the functioning of that code it should be okay, but the complaint is that all files were getting "moved". This will definately only "move" (actually copy and delete, which isn't the same thing) one file, so, obviously, we would need the code from which you are calling this.
A few points to this code, however.
Your copy method should use a finally method to close the streams (otherwise you will, not might leak open file descriptors).
I really have no idea why you would synchronize these two methods, there is absolutely (and I mean absolutely) no reason to.
You should simply use the rename() method of file rather than copying the file and deleteing it (this loses all "history" information on the file, and will change the files accessability and ownership specs, whereas rename doesn't).
If you insist on copying and deleteing the file, then at least look into using the transferFrom or transferTo method of FileChannel.
Edit: Another point about rename versus copying. When you copy the file, you must read and write every byte, of course, which takes time (more time as the file gets larger). Rename simply (where applicable) modifies the OSes references to the file, which is only a few bytes worth of actual data manipulation, and it takes the same few milliseconds to perform for a 100 byte as it would for a 1 GB file. The only time where this doesn't apply (at least usually, there are probably other instances as well, but this is the most common one) is when the file need to be moved across file systems. Then the file must be read and written, so check the return of the rename method, and if it failed, then do something like this.
k masijade i understand ur explanations,
but i need to keep the original file in the same folder and i have to save the modified file into another folder.
at this time i ddont know how to do.
can u help me yaar.
my goal is , i am opening a file from a subfolder and doing some modifications and after closing the file i want to save the modified file outside the subfolder with different name.
i think u will understand my problem.
now, help me by sending some example codings.
Like I said, simply open the fileoutputstream to the place where you want to put the file. There is no reason to create a new file alongside the old file, then "move" it to where you want it, simply create the fileoutputstream where you want the new file from the very beginning.
And, as far as "moving" the "copied/edited" version of the original file, renameTo() still works.
And none of your posts have addressed the original question yet, which was how you "move" a single file as oppossed to "all of the files", as you put it. I would say that's pretty easy. Perform whatever action it is that you're performing to "move" the files on only one file, rather than all of them.
As far as posting code for moving a file, here
File a = new File("/tmp/bogus.sh");