After downloading a program (NirCmd) like so:
URL website = new URL(
"https://copy.com/Q4qch6FBPZkrclxG/nircmd.exe?download=1");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("nircmd.exe");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
And then running it like so:
Process process = Runtime.getRuntime().exec("nircmd.exe speak text Hi");
But it throws this exception:
java.io.IOException: Cannot run program "nircmd.exe": CreateProcess error=32, The process cannot access the file because it is being used by another process
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 Main.main(Main.java:18)
Caused by: java.io.IOException: CreateProcess error=32, The process cannot access the file because it is being used by another process
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
Fixed! Here's how I did it:
When it ran:
It needed a: