I want to copy some files from my computer to a server-location.
My computer is running on Windows-7. My files are stored in :
C:\Transfer\
The server location where I have to transfer the files is :
\\server1\myname\TransferData\
I want to do this using Java. I have tried some commands like this on my command-prompt :
pushd \\server1\myname\TransferData\
Z:\> mv C:\Transfer\* Z:\
For some reason, this works when done manually & DOES NOT work through java. I get IOException.
Java Code I have been using :
Process proc = Runtime.getRuntime().exec("pushd \\server1\myname\TransferData\");
proc.waitFor();
// once this server location gets mounted - i was thinking of moving the file. that part works through java.
Error I get is this :
Exception in thread "main" java.io.IOException: Cannot run program "pushd": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.data.Main.main(Main.java:34)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
I have also tried this :
Process proc = Runtime.getRuntime().exec("cmd pushd \\server1\myname\TransferData\");
proc.waitFor();
&
Process proc = Runtime.getRuntime().exec("cmd \c pushd \\server1\myname\TransferData\");
proc.waitFor();
&
Process proc = Runtime.getRuntime().exec("cmd.exe pushd \\server1\myname\TransferData\");
proc.waitFor();
The above does not throw an exception. And does not mount the server location to my computer also.
I have write access in the server. I really need a solution to my problem. Thanks.