Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.File;

public class Main {

    public static void main(String[] args) {
        try {
            String[] cmdArray = new String[2];
            // the program to open
            cmdArray[0] = "notepad.exe";

            // txt file to open with notepad
            cmdArray[1] = "test.txt";

            File dir = new File("c:/");

            String[] envArray = new String[2];
            envArray[0] = "";
            envArray[1] = "";

            Runtime runTime = Runtime.getRuntime();

            Process process = runTime.exec(cmdArray, envArray, dir);

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

    }
}