⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 java的经典例子
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -