Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        try {
            // create a new process
            Process p = Runtime.getRuntime().exec("notepad.exe");

            // get the input stream of the process and print it
            InputStream in = p.getInputStream();
            for (int i = 0; i < in.available(); i++) {
                System.out.println(in.read());
            }

            // wait for 10 seconds and then destroy the process
            Thread.sleep(10000);
            p.destroy();

        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}