Overview
Append, read, or read lines with filters from a text file.
Key Features & Functionality
Smart Services:
Functions
Hi,
For Append text to file smart service, would it be better to append the content without loading the entire content into a variable? The following seem to be better approach to avoid loading the data into memory.
BufferedReader reader = new BufferedReader(new InputStreamReader(documentInputStream));Approval a = cs.createVersion(doc, ContentConstants.UNIQUE_NONE);Long newVersionId = a.getId()[0];Document newDoc = cs.download(newVersionId, ContentConstants.VERSION_CURRENT, false)[0];
try (DocumentOutputStream documentOutputStream = newDoc.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(documentOutputStream))) {
String line; while ((line = reader.readLine()) != null) { writer.write(line); writer.newLine(); } writer.write(textToAppend); // append directly, no memory buildup}