Java runtime.exe C () Calling the Copy command causes of error = 2
Today, I wrote a Java program for the lab project.Program. Copy the file. JDK provides this function. It is unnecessary to write a class by yourself. You can directly call copy in Windows command line.
Here runtime.getruntime(cmd.exe C (string cmd) is used ).
In the same way, the command line runs normally.
However, an error occurred while running the Java program:
Java. Io. ioexception: CreateProcess: Copy D:/recall.txt E:/error = 2 At java. Lang. processimpl. Create (native method) At java. Lang. processimpl. <init> (unknown source) At java. Lang. processimpl. Start (unknown source) At java. Lang. processbuilder. Start (unknown source) At java.lang.runtime.exe C (unknown source) At java.lang.runtime.exe C (unknown source) At java.lang.runtime.exe C (unknown source) At edu. zju. generator. T. Main (T. Java: 43) |
Error cause:
Copy is not a separate program. Run the Copy command under the command line. The writing method is .exe/C copy... Also, copyis a functional module of cmd.exe.
Exec (string cmd) executes an existing program file. Therefore, an error occurs.
Exec ("cmd.exe/C copy...") is OK.
Forward by http://memset.spaces.live.com/blog/cns! 842ffa698e149941! 152. Entry