Direct CMD output to a file
Dear Forum
I want to direct the output of command "dir" to a file using java..
Code:
import java.io.*;
public class Exec {
public static void main(String[] args) throws IOException {
Process p = Runtime.getRuntime().exec("cmd /c start dir");
// OutputStream outstr = p.getOutputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedWriter fw = new BufferedWriter(new FileWriter("c:\\cmdout.txt"));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
fw.write(line);
}
fw.close();
}
}
direct the cmd command to cmdout.txt file
Can you please help...