Pregunta

I have an issue for my application.

I want to convert selected .java file to .class file at same path.

for that i am using:

   File directoryPath = new File(".");
    String command ="cmd.exe /C "+ directoryPath.getCanonicalPath()+"\\javac UpsOfferDataDaily.java"; 
                Runtime.getRuntime().exec(command);

any thing strange with that??

It Can't execute my command successfully.

directory path will be same as the .java is situated.

what should i do...

Thanks in advance:

¿Fue útil?

Solución

Try this....javac is already in my path. So i jus gave the filename. Errors will be shown by the error stream, if any...It worked for me!!!

String command ="cmd.exe /C "+ "javac C:\\student\\workspace\\javaproject\\Testing\\src\\TestCalculator.java"; 
        Process p = Runtime.getRuntime().exec(command);
        InputStream i = p.getErrorStream();
        int c;
        while((c=i.read())!=-1)
            System.out.print((char)c);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top