io.github.laskowski.shell.script.TXTWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shell-commander Show documentation
Show all versions of shell-commander Show documentation
Library to launch .bat and .sh scripts of your choice with different configurations. Allows you to read tasks and services output from terminal
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