/home/main/o" name="description">

import java.io.BufferedReader; import java.io.InputStreamReader; public class Example { public static void main(String args[]) { String s = null; String cmd = "ls > /home/main/output/f.txt"; try { Process p = Runtime.getRuntime().exec(cmd); int i = p.waitFor(); if (i == 0){ BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((s = stdInput.readLine()) != null) { System.out.println(s); } } else { BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command while ((s = stdErr.readLine()) != null) { System.out.println(s); }
}
}
catch (Exception e) {
System.out.println(e);
}
}
} while executing ls > /home/main/output/f.txt from terminal in linux its creating f.txt.But cant run from java program ls: cannot access >: No such file or directory error is displayed .No f.txt is created.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.