Reputation: 41
Under cmd.exe, I can do like this:
dir *.*|grep ....
I want to do this to java program
dir *.i|java test
What I should do in my java test class?
Upvotes: 4
Views: 159
Reputation: 15723
Handle the System.in
in Test
class,here is the example:
public class Test {
public static void main(String[] args) {
InputStream in = System.in;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int next = in.read();
while (next > -1) {
bos.write(next);
next = in.read();
}
bos.flush();
byte[] bytes = bos.toByteArray();
System.out.println("output:" + new String(bytes));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Upvotes: 1