469,312 Members | 2,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Copy Paste using Java

How do i Copy A file to another destination while overwriting the existing file in the destination folder??


what class should i use?


e.g.

c:\ pic1.jpg copy to d:\pic1.jpg

thanks in advance
Feb 4 '08 #1
3 10484
r035198x
13,262 8TB
How do i Copy A file to another destination while overwriting the existing file in the destination folder??


what class should i use?


e.g.

c:\ pic1.jpg copy to d:\pic1.jpg

thanks in advance
What happened when you tried the advice given in this thread?
Feb 4 '08 #2
You can use below code to copy file from one folder to another

FileChannel ic = new FileInputStream("source file name")).getChannel();
FileChannel oc = new FileOutputStream("destination file name").getChannel();
ic.transferTo(0, ic.size(), oc);
ic.close();
oc.close();
Feb 25 '08 #3
sukatoa
539 512MB
How do i Copy A file to another destination while overwriting the existing file in the destination folder??


what class should i use?


e.g.

c:\ pic1.jpg copy to d:\pic1.jpg

thanks in advance

Another way to do that is,

Delete the file at the destination folder if it exists,(file transfer failed if exists)

[PHP]new File(Destination File).delete();[/PHP]

Transfer the new file from source to destination,

[PHP]sourcefile.renameTo(new File(Destination directory, string representation of the source file));[/PHP]

It's a filetransfering only...
If you want to remain the sourcefile to its original directory...
Just open it from the new destination and save it again to the original destination...

if you implement it in automatic, then you can test it, but if in manual, use JFileChooser...

Correct me if im wrong,
Sukatoa, Shadow Shaman...
Feb 25 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Bob T Bunny | last post: by
reply views Thread by Nelgonde | last post: by
4 posts views Thread by Legendary Pansy | last post: by
7 posts views Thread by lgbjr | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.