echo is not a real command in the sense that it has a binary that you can run. It is a built-in function of shells.
You could try running a shell like cmd.exe in Windows or sh in Linux/Mac/Unix, and then passing the command to run as a string.. Like using 'bash', you can do this:
edit because redirection is a little different using Runtime
To do redirection correctly, you should be using the form of exec that takes a String[].
Here's a quick example that does work with redirection.
public class RunTest {
public static void main(String[] args) throws Exception {
String [] commands = { "bash", "-c", "echo hello > hello.txt" };
Runtime.getRuntime().exec(commands);
}
}
But if you just wanted to create a file, you could create the file with Java's own API rather than use Runtime.