public static void main (String args[]) throws Exception { FileOutputStream fos = new FileOutputStream("c:/dir.txt"); try { String strExec = "cmd /c dir"; Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(strExec); InputStream is = process.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while((line = br.readLine()) != null) { fos.write(line.getBytes()); } } catch(Exception exc) { exc.printStackTrace(); } finally { fos.close(); } System.out.println("fertig"); }