Text File Utilities

Overview

Reads data from a text file (any extension encoded as text) into a string, with an option to preserve line breaks.

 

Anonymous
Parents
  • 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
    }

Comment
  • 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
    }

Children
No Data