• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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?
0
tbboyett
Asked:
tbboyett
  • 4
  • 2
1 Solution
 
CEHJCommented:
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
0
 
tbboyettAuthor Commented:
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?
0
 
CEHJCommented:
>>does the line File dest = new File("\\\\server_name\\sharename\\destfile"); automatically copy the file?

No

>>do i just create an outputstream to the location i want on the client machine?

You create a FileOutputStream to the one just create and then write to it, reading from the source

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
CEHJCommented:
Typo

just create=just created
0
 
tbboyettAuthor Commented:
Works great :) thanks CEHJ
0
 
CEHJCommented:
:-)
0
 
Nguyen Huu PhuocSenior ManagerCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now