I am a relatively novice programmer who can code in HTML, Python, and Java, and I decided to challenged myself to write a block of Java code(using JCreator). I came up with the following challenge:
Design a program in which it would take a .exe file, copy it to a folder (which could be easily changed though a variable), run the file, then delete the file, then continue to do the same process throughout every sub-folder in that directory
I proceeded to write the program, and got the parts of the program to run the exe and to find all of the sub-directories working (with help from stack-overflow, of course). I put all of them together, in addition to the part to copy the .exe file using Files.copy. Every time I run the program, it returns an error.
Part of my code to copy the file, run it, then delete it. I use variables such as "location" and "destination" to allow for easy expansion to the program, and these variables are defined earlier in the program
public static void EXETestGo(final File folder){
String destination = folder.getAbsolutePath(); //place to move the exe file; changes each time that the method is called
String location = "C:/file.exe"; //origin of the exe file
String runLocation = destination + "/" + "file.exe"; //place of the moved exe file
|
try{
Files.copy(location, destination, REPLACE_EXISTING);
Runtime r = Runtime.getRuntime(); //These two combined
Process p = r.exec(runLocation); //'runs' the exe file
deleteIfExists(runLocation); //deleates file
}catch(IOException ex){
//catches the failed process if it fails
System.out.println (ex.toString()); //prints out the problem
System.out.println("Error 404");
}
Both of these pieces of code are from/used in the same method, so there should not be any problems regarding local variables and whatnot
Any feedback/help would be greatly appreciated!
EDIT: After being run, it returns the "cannot find symbol" error
EDIT #2: I realize that I did not include my imports, which my be the source of the problem My imports:
import java.io.File;
import static java.nio.file.StandardCopyOption.*;
import java.lang.Runtime;
import java.lang.Process;
import java.io.IOException;
import java.lang.InterruptedException;