473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 10764
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

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

Similar topics

2
by: Bob T Bunny | last post by:
Hi all, I am trying to copy a form that is in one frame, using a button on another frame. The form has a couple of tables inside it. I can get it working when the button is in the same frame,...
0
by: Nelgonde | last post by:
Apologies for the basic nature of this question but I'm very inexperienced in Java. I've been given the task of disabling the cut/copy/paste functions (Ctrl-X,C & V) in our java dialogs and...
4
by: Legendary Pansy | last post by:
I was checking out the 101 C# Samples, specifically Windows Forms - Use the Clipboard. I took a look at the code for a while, and I understand what the program is doing with the cut, copy, pasting...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: veera372 | last post by:
i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard option... but i...
2
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard...
1
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard...
0
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard...
6
by: rakeshvthu | last post by:
hi all, can we disable the copy and paste option in edit menu bar of browser my customer does not want copying using any technique so can any one help how to disable that options copy and...
13
by: carlos123 | last post by:
ok the following code , is the code for my program, basicly, i use bluej, so i can just copy and paste some code into the forums and someone else can copy it in to their editor, so basicly i want...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.