JAVA/CORBA CLASSES


Examples: close method
This example gets information on the normal files in a directory by opening each file as a stream. The agent reuses the same NotesStream object by opening and closing it for each file.

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

public class JavaAgent extends AgentBase {

 public void NotesMain() {

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

     // (Your code goes here)
     Stream stream = session.createStream();
     int bytes = 0;
     File directory = new File("C:\\StreamFiles");
     String[] files = directory.list();
     for (int i = 0; i < files.length; i++) {
       if (stream.open(directory + "\\" + files[i])) {
         bytes = bytes + stream.getBytes();
         stream.close();
       }
       else
         throw new NotesException
           (NotesError.NOTES_ERR_FILEOPEN_FAILED, "Open failed");
     }
     System.out.println("Number of files = " + files.length);
     System.out.println("Total bytes = " + bytes);
     
   } catch(NotesException e) {
     e.printStackTrace();

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

See Also