You can use ProcessBuilder class as follows:
public static void main(String [] args) throws IOException
{
String[] command = {"CMD", "/C", "dir"};
// ProcessBuilder will execute process named 'CMD' and will provide '/C' and 'dir' as command line arguments to 'CMD'
ProcessBuilder pbuilder = new ProcessBuilder(command);
Process process = probuilder.start();
//Wait for process to finish
try
{
int exitValue = process.waitFor();
System.out.println("\n\nExit Value is " + exitValue);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}