Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    /**
     * Create a script file to run one command, with an arbitrary name based on the system time
     * @param cmmd Command for the script to run
     * @return The file
     * @throws IOException 
     */
    public static File createScriptFile(String cmmd) throws IOException {
        return createScriptFile(cmmd, null);
    }

    /**
     * Create a script file to run one command
     * @param cmmd Command for the script to run
     * @param fileName The file name
     * @return The file
     * @throws IOException
     */
    public static File createScriptFile(String cmmd, String fileName) throws IOException {
        String f = fileName == null ? "script_" + System.currentTimeMillis() : fileName;
        FileWriter w = new FileWriter(f);
        w.write(cmmd + "\n");
        w.close();
        File file = new File(f);
        file.setExecutable(true, false);
        return file;
    }
}