Link to home
Start Free TrialLog in
Avatar of tbboyett
tbboyettFlag for United States of America

asked on

Copy files and paste to a different directory

In java how can I copy an entire file regardless of the file type and paste it to a new location?

My goal here is a file is exported to a location on the server machine and I want to use java to copy that file and paste in on a client machine.

Is this possible through java?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Is your server on the same network? If so you can do

File dest = new File("\\\\server_name\\sharename\\destfile");

and copy in the usual way
Avatar of tbboyett

ASKER

The server is on the same network

>> and copy in the usual way

does the line File dest = new File("\\\\server_name\\sharename\\destfile"); automatically copy the file?
and if so do i just create an outputstream to the location i want on the client machine?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Typo

just create=just created
Works great :) thanks CEHJ
:-)
I don't think it is very easy as CEHJ posting.
1.The source and the destination machine are same network which is not enough to locate file by:
 \\\\server_name\\sharename\\destfile.
It is depend on what platform they are running on and the policy of the destination machine.
2. I think you should install an FTP server on client machine. You visit here to download        
Quick ’n Easy FTP Server 3.0 (freeware)
http://www.pablosoftwaresolutions.com/html/quick__n_easy_ftp_server.html
It needn't install, just execute the exe file. It is very easy.
3. Now you use http://jakarta.apache.org/commons/net/ Jakarta Common Net to develop your Java program which is charge of FTP client role.
If your server and client are using Microsoft Windows.
You should map the destination folder into network drive.
My Computer >Tool > Map Network Drive >chose a drive letter (take example:Z)> Browse to locate the folder on the client machine.
Now you write a Java program to copy a folder from place to Z:.
It just a program copy folder in local machine.
Phuoc H. Nguyen