-
Overwrite an existing file in java....
Hi !!!
I want to overwrite an existing file with the new version of the same file name.
Right now what i am doing is like below:
boolean success = file.renameTo(new File(destxmldir, file.getName()));
But it does not overwrite if the same file exists before....
I just want to overwrite it by default whether the file changed or not...
Please help me...
Thanks in advance.....
-
Re: Overwrite an existing file in java....
13 views...not a single reply yet...
-
Junior Member
Re: Overwrite an existing file in java....
Hi,
renameTo() will not work for overwriting a file. It will return false if it could not move files from source to destination.
You should have done this in a work around way:
check if file exists,
if file does notexists, create a new file/move the file in the destination location.
Else, if file exist, write the data from the source file to the destn file using streams (either way, appending or writing newly) to the same file ..
just a thought .. u can very well share if you have any other good logic than this.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules