main.java
来自「java的经典例子」· Java 代码 · 共 25 行
JAVA
25 行
import java.io.*;
class Main {
public static void main(String[] args) {
try {
String cmd = "ls";
// read first 5 lines from 'ls' and then destroy process
Process child = Runtime.getRuntime().exec(cmd);
InputStream in = child.getInputStream();
int c, newline = 0;
// read first 5 lines and then stop
while ((c = in.read()) != -1 && newline < 5) {
char ch = (char)c;
System.out.print(ch);
if (ch == '\n')
++newline;
}
in.close();
child.destroy(); // destroy process
} catch (IOException e) {
System.err.println(e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?