Examples: setContents method

This agent reads from a file using java.io.InputStreamReader.

import lotus.domino.*;
import java.io.*;

public class JavaAgent extends AgentBase {

  public void NotesMain() {

    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      // (Your code goes here)
      String inPath = "c:\\StreamFiles\\readme.txt";
      FileInputStream fis = new FileInputStream(inPath);
      InputStreamReader isr = new InputStreamReader(fis, "ASCII");
      Stream inStream = session.createStream();
      inStream.setContents(isr);
      Database db = agentContext.getCurrentDatabase();
      Document doc = db.createDocument();
      doc.replaceItemValue("Form", "Main Topic");
      doc.replaceItemValue("Subject", inPath);
      doc.replaceItemValue("Body", inStream.readText());
      inStream.close();
      doc.save(true, true);
      
    } catch(NotesException e) {
      e.printStackTrace();

    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}