Skip to content

qie.appendToFile

Signature: qie.appendToFile(file, value, shouldCreatePath*)

Returns: void

Appends value to the contents of file. If file does not exist, it will be created.

Parameters

Type Name Description Default
String, File, or NetFile file the file to append to. This can be either a string representing the file's full path and file name (i.e. 'c:\\temp\\file.txt'), a java.io.File object or a com.qvera.qie.utils.NetFile object.
String or byte[] value the contents to be appended to the file
Boolean shouldCreatePath* (optional) true, to create the path of the file if it doesn't exist; false, otherwise false

Example

// Example: file as String path, value as String
qie.appendToFile(
   "/tmp/mine.txt",                                         // file as String path
   "Well, hello there. I hope you are having a great day!", // value
   true                                                     // should create path
);


// Example: file as File, value as String
var fileObject = qie.newFile("/tmp/mine-file.txt");      // java.io.File
qie.appendToFile(
   fileObject,
   "This line was appended using a File object.",        // value
   true                                                  // should create path
);


// Example: file as String path, value as byte[]
var byteValue = [
   84,104,105,115,32,119,97,115,32,97,112,112,101,110,100,101,100,32,97,115,32,98,121,116,101,115,46
]; // "This was appended as bytes."
qie.appendToFile(
   "/tmp/mine-bytes.txt",     // file as String path
   byteValue,                 // value as byte[]
   true                       // should create path
);