JAVA/CORBA クラス
例:readText メソッド
1. 次のエージェントは、テキストファイルを読み込み、その内容を現在のデータベース内の新規文書の Body アイテムに保存します。次のエージェントは、Subject アイテムの内容に対してファイル名を使用します。
import lotus.domino.*;
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";
// Get the input file
Stream inStream = session.createStream();
if (inStream.open(inPath, "ASCII")) {
if (inStream.getBytes() > 0) {
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);
}
else
System.out.println("Input file has no content");
}
else
System.out.println("Input file open failed");
} catch(NotesException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}
2. 次のエージェントは、最初の例に似ていますが、一度に 1 行ずつファイルを読み込みます。エージェントは、ストリームの最後まで新規文書の Body アイテムにテキストを追加します。
import lotus.domino.*;
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";
// Get the input file
Stream inStream = session.createStream();
if (inStream.open(inPath, "ASCII")) {
if (inStream.getBytes() > 0) {
Database db = agentContext.getCurrentDatabase();
Document doc = db.createDocument();
doc.replaceItemValue("Form", "Main Topic");
doc.replaceItemValue("Subject", inPath);
RichTextItem body = doc.createRichTextItem("Body");
do {
body.appendText(inStream.readText(
Stream.STMREAD_LINE,
Stream.EOL_CRLF));
} while (!inStream.isEOS());
inStream.close();
doc.save(true, true);
}
else
System.out.println("Input file has no content");
}
else
System.out.println("Input file open failed");
} catch(NotesException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}
関連項目
readText メソッド
用語集
フィードバック
ヘルプ
または
プロダクトユーザビリティ
ヘルプの使い方
すべてのヘルプ項目
用語集