I faced this problem some time ago, but the solution Mr.HaghighatKhah recommended (and also using class "ProcessBuilder") does not work for all the commands executed in cmd environment.
for instance consider the command "copy d:\music\someFile.txt d:\downloads"
executed in cmd environment correctly, but when running the following code you'll notified the occurrence of this exception : "Exception in thread "main" java.io.IOException: Cannot run program "copy": CreateProcess error=2, The system cannot find the file specified"
<code>
String cmd = "copy d:\\music\\someFile.txt d:\\downloads";
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
</code>