朋友们,我想从指定路径的机器访问属性文件。对于java Agent,我使用了Properties方法并从属性文件中提取了数据。但现在我希望它在莲花中完成。我尝试使用属性方法,但它没有工作,所以我想用下面的代码读取属性。
'Dim ColFileName As String
'ColFileName="C:\abcd.properties"
Open ColFileName For Input As 1
Do While Not EOF(1)
Line Input #1,txt$
MsgBox "TEXT FILE:"+txt$
在属性文件中,我将其写为 COL =启动
我希望在java中使用getProperty方法获取col的属性与lotusscript相同。 我添加了上面的代码,但它无法正常工作。谁能说出我犯的错误。
答案 0 :(得分:1)
在选项中
%Include "lserr.lss" 'This is just a list of constants.
在某处添加这些功能:
%REM
Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
<dl>
<dt>sPath</dt><dd>Filepath of the file to be opened/created.</dd>
<dt>bTruncate</dt><dd>Boolean. True if file is for output and any existing file should be replaced rather than appended to.</dd>
<dt>bConfirmExists</dt><dd>Boolean. If True, and the opened file is empty, then an ErrFileNotFound error will be thrown.</dd>
</dl>
%END REM
Function fstreamOpenFile(sPath As String, bTruncate As Boolean, bConfirmExists As Boolean) As NotesStream
Dim session as New NotesSession Dim stream As NotesStream
Set stream = session.Createstream()
If Not stream.Open(sPath) Then Error ErrOpenFailed, {Could not open file at "} + sPath + {"}
If bConfirmExists And stream.Bytes = 0 Then Error ErrFileNotFound, {File at "} + sPath + {" is missing or empty.}
If bTruncate Then Call stream.Truncate()
Set fstreamOpenFile = stream
End Function
Function fsPropertyFileValue(sFilePath As String, sPropertyName As String, sDefaultValue As String) As String
On Error GoTo ErrorQuietly
Dim stream As NotesStream
Dim sLine As String
Dim sLeft As String
Dim iLeftLen As Integer
Set stream = fstreamOpenFile(sFilePath, False, True)
sLeft = sPropertyName + "="
iLeftLen = Len(sLeft)
Do
sLine = stream.Readtext
If Left(sLine, iLeftLen) = sLeft Then
fsPropertyFileValue = Right(sLine, Len(sLine) - iLeftLen)
Exit Function
End If
Loop Until stream.Iseos
ReturnDefault:
fsPropertyFileValue = sDefaultValue
Exit Function
ErrorQuietly:
Print Now, Error$
Resume ReturnDefault
End Function
(注意:我没有测试/调试过fsPropertyFileValue。注释中的html标签是因为,在编辑代理或脚本库时,设计器客户端将解析并显示HTML标记。)
然后,您可以使用fsPropertyFileValue("C:\abcd.properties", "col", "start")
获取C:\ abcd.properties中col属性的值,如果失败,则使用“start”。