| Author |
using windows command line to copy and paste. getting file not found error
|
john bullwinkle
Greenhorn
Joined: Nov 04, 2010
Posts: 4
|
|
i'm needing to copy and paste + rename a file from one dir to another. i tried doing it in strictly java code, i was successful, but when opening the file, it is corrupt. so i decided to switch my method to just pass a copy line to the windows command line. i have successfully ran the copy line in the windows command prompt, however am getting an error in my code when doing it. here is the code
here is the output i'm getting
copy = COPY "C:\serviceTech\config\Tech\LPEquipmentLease_distributed.pdf" "C:\serviceTech\CompletedForms\ItemLPEqpLsetest_test_test.pdf"
java.io.IOException: Cannot run program "COPY": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at servicetech.SelectionScreen.getFileNames(SelectionScreen.java:338)
if i copy everything after the 'copy =' line into the command line, it works fine. so i'm unsure why i'm getting this cannot find the file specified.
thanks in advance for your help.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Welcome to the Ranch, John!
COPY is not an application; it's a built-in command of CMD.EXE. You'll need to run that using the /C flag. Run CMD /? for more info.
But I'd first investigate why the files became corrupted. Can you show us the old Java copy code?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
john bullwinkle
Greenhorn
Joined: Nov 04, 2010
Posts: 4
|
|
thanks for the help. not sure if i fully understand the way i should format the line.
i tried this:
it runs, however doesn't copy the file.
here is the original code i used to copy. option1-3 is strings from user input
|
 |
john bullwinkle
Greenhorn
Joined: Nov 04, 2010
Posts: 4
|
|
|
nvm. i forgot to put the /c flag in there.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
Please avoid abbreviations like "nvm".
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
And before we forget, When Runtime.exec() won't.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
|
You can use Execlibrary from the Apache Commons. Its pretty handy utility for running external programs from Java.
|
Mohamed Sanaulla | My Blog
|
 |
 |
|
|
subject: using windows command line to copy and paste. getting file not found error
|
|
|