[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy files and paste to a different directory

Posted on 2006-05-26
7
Medium Priority
?
210 Views
Last Modified: 2012-08-14
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
Comment
Question by:tbboyett
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16769200
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
 
LVL 5

Author Comment

by:tbboyett
ID: 16769272
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 16769297
>>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 16769300
Typo

just create=just created
0
 
LVL 5

Author Comment

by:tbboyett
ID: 16769354
Works great :) thanks CEHJ
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16769364
:-)
0
 
LVL 6

Expert Comment

by:phuocnh
ID: 16769489
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question