Siten
Siten

Reputation: 4533

how convert a particular .java to .class with coding?

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:

Upvotes: 0

Views: 548

Answers (2)

Shashank Kadne
Shashank Kadne

Reputation: 8101

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);

Upvotes: 2

Related Questions