This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes using windows command line to copy and paste. getting file not found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using windows command line to copy and paste. getting file not found error" Watch "using windows command line to copy and paste. getting file not found error" New topic
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: 19656
    
  18

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 - OCEEJBD 6
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: 38088
    
  22
Please avoid abbreviations like "nvm".
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

And before we forget, When Runtime.exec() won't.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

You can use Execlibrary from the Apache Commons. Its pretty handy utility for running external programs from Java.


Mohamed Sanaulla | My Blog
 
Consider Paul's rocket mass heater.
 
subject: using windows command line to copy and paste. getting file not found error
 
Similar Threads
Runtime getRuntime() exec(String command) - How does this work?
Compile and create instance of a new java program from existing java program
Process
.sh file not found
Reg:Executing Commands