This is example to execute the dos command and display the list of the file in the Specified Drive.
package com.jsl.example; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class ExecutingwindowsCommands { public static void main(String[] args) { try { Process process = Runtime.getRuntime().exec("cmd /c dir D:\\"); InputStream in = process.getInputStream(); InputStreamReader ins=new InputStreamReader(in); BufferedReader br = new BufferedReader(ins); String data = null; while ((data = br.readLine()) != null) { System.out.println(data); } } catch (Exception e) { System.out.println(e); } } }Sample Output: