This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Copying file from one PC to the other PC on a network.

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
Iam unable to move /copy a file from one machine to other on the network using this code.
class MoveFile
{
public static void main(String ar[])
{
try
{
Runtime rn=Runtime.getRuntime();
Process move =rn.exec("cmd /C move C:/text.txt I:/Test/text.txt") ;
move.waitFor() ;
}
catch(Exception e)
{
System.out.println("Error"+e);
}
}
}
Where C is the localdrive and I: is the mapped drive of the second machine.
This code doesnt throw any Runtime exception but the file is not coppied .

Thanks
Swapna.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swapna,
According to what you have posted, I don't think the command you have written:

would work from the Windows command prompt either -- although I admit I haven't tried it myself.
[Note: I assume you are on a Windows platform.]
As far as I know, the backslash character ("\") is used as the path separator on Windows platforms -- and not the [forward] slash character ("/") as in the code snippet you have supplied. However, remember that java interprets the backslash as an "escape" character, so your command line should be like this (I think):

Again, I have not tested this code.
However, I would also like to point out, that with mapped, network drives, you can use pure java to copy the files (rather than using the "exec()" method in class "Runtime"), using the classes in the "java.io" package. Assuming the file you wish to copy is a text file, you can use the "java.io.BufferedReader" and "java.io.BufferedWriter" classes. Here is some sample code (which is untested):

Again, the above code is completely untried. Please check the relevant javadocs first, in order to verify the above.
Hope this helps.
Good Luck,
Avi.
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swapna,
I just remembered. If you prefer using the "exec()" method (in "java.lang.Runtime"), then I suggest you read this JavaWorld article (assuming you haven't already):
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Good Luck,
Avi.
 
What's that smell? Hey, sniff this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic