it's probably a stupid question but i need help.(i tried to solved it myself for 3 hours , so please do not block me) i'm trying to compile java files in a different directory.
i'm getting a folder with some .java files and i need to compile them. with:
public boolean complie() throws Exception{
Process pro = Runtime.getRuntime().exec("javac -cp "+location+"/*.java");
String line = null;
BufferedReader in = new BufferedReader(
new InputStreamReader(pro.getErrorStream()));
while ((line = in.readLine()) != null) {
System.out.println(name + " " + line);
}
}
but i'm getting errors.
the errors are point to the usage of other class in the folder. (error: cannot find symbol
)
when i'm trying to compile in the CMD after navigating to the folder with "javac *.java
", there is no errors.
please help me!
update:
i have trid:
File pathToExecutable = new File(location );
ProcessBuilder builder = new ProcessBuilder( pathToExecutable.getAbsolutePath(),"javac *.java");
builder.directory( new File( location ).getAbsoluteFile() ); // this is where you set the root folder for the executable to run with
builder.redirectErrorStream(true);
Process process = builder.start();
Scanner s = new Scanner(process.getInputStream());
StringBuilder text = new StringBuilder();
while (s.hasNextLine()) {
text.append(s.nextLine());
text.append("\n");
}
s.close();
but getting CreateProcess error=5, Access is denied
error (i'm running my IDE as administrator)