Processor to add content to a (existing) file. The content is added to the end of the file.
The inputs:
Filename: the file name of a file, if the file does not exists, a new file is added
Content: the string to append
NewLine [default = true]: if true, a newline is added to the end of the line (useful if you want to add a record each time)
true
import java.util.concurrent.Semaphore;
if(bsh.shared.appendFileSemaphore == void){
bsh.shared.appendFileSemaphore = new Semaphore(1);
}
PrintStream stream;
try{
bsh.shared.appendFileSemaphore.acquire();
stream = new PrintStream(new FileOutputStream(Filename, true));
if(NewLine == void){
NewLine = "true";
}
if(Boolean.parseBoolean(NewLine)){
stream.println(Content);
} else{
stream.print(Content);
}
} finally{
if(stream != void){
stream.close();
}
bsh.shared.appendFileSemaphore.release();
}
Filename
Content
NewLine