All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.laskowski.shell.script.TXTWriter Maven / Gradle / Ivy

Go to download

Library to launch .bat and .sh scripts of your choice with different configurations. Allows you to read tasks and services output from terminal

There is a newer version: 2.0.6.1
Show newest version
package io.github.laskowski.shell.script;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class TXTWriter {
    private BufferedWriter writer;
    private File outputFile;

    public TXTWriter(File dir, String fileName) {
        try {
            outputFile = new File(dir, fileName);
            outputFile.getParentFile().mkdirs();
            outputFile.createNewFile();

            writer = new BufferedWriter(new FileWriter(outputFile));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void write(String string, Object... arguments) {
        doWrite(String.format(string, arguments));
    }

    public void newLine() {
        doWrite(System.lineSeparator());
    }

    public File save() {
        try {
            writer.flush();
            writer.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        outputFile.setExecutable(true);
        return outputFile;
    }

    private void doWrite(String string) {
        try {
            writer.write(string);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy