Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class Main extends Thread {
    Process ps = null;

    public Main() throws Exception {
        ps = Runtime.getRuntime().exec("java Test");
    }

    public void send() throws Exception {
        OutputStream ops = ps.getOutputStream();
        while (true) {
            ops.write("hello\r\n".getBytes());
        }
    }

    public void run() {
        try {
            InputStream in = ps.getInputStream();
            BufferedReader df = new BufferedReader(new InputStreamReader(in));
            while (true) {
                String sLine = df.readLine();
                System.out.println(sLine);
            }
        } catch (IOException ie) {
            System.out.println(ie);
        }
    }

    public static void main(String[] args) throws Exception {
        Main e = new Main();
        e.start();
        e.send();
    }
}

class Test {
    public static void main(String[] arg) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String sLine = bf.readLine();
            System.out.println("::" + sLine);
        }
    }
}