How to Write in property file using java service?

Hi,

I want to update property file at runtime using java/flow service. I will pass the Name of the parameter which needs to be updated and value which needs to be set. Is there any inbuilt service to achieve this?

Please let me know if any concern.

Regards,

Mangat Rai

Hi,

Please download PSUtilities2 package from advantage samples and utilities section.
you will get the service there.

Also PSUtilities2 services are not regression tested so test customise it according to your need and test it thoroughly before putting it to live env.

Regards,
Sumit

Thanks a lot Sumit…
Surely i will try it. If i face any issue will get back here :proud:

Sumit, I am not able to find PSUtilities2 package. Can you please tell me the exact path

Hi,

First of all i would like to mention that i am using webMethods 6.5
I downloaded PSUtilities 2.0 version package and installed the same. But i could not find any service which takes care of setting property. Can any one tell me exact name and path of the service if it exist in PSUtilities package.

I am mentioning my requirement once again.
I want to change the value of a parameter in property file at run time. It means I want to update property file at run time. Piece of code should over write the earlier value of the parameter in property file with the new value which will be passed as input to service. Parameter name will also be passed as input.

I want to achieve it using Java service/ Flow service.

Thanks in Advance.

Regards,
Mangat Rai :uhoh:

Hi Mangat,

There is no inbuilt service.
But this is fairly easy. You might not get the code exactly what you want in PSUtilities but you will get an idea.

A simple google search would give you many sample.
one such sample : [url]http://www.roseindia.net/java/example/java/util/WriteProperty.shtml[/url]

Regards,
Sumit

Hi Sumit,

Thanks a lot…
I have one question… I want to update property file of a flow in webMethods i.e a “.cnf” file.

Does property class in java support this extension or it supports only .properties extension?

Regards,
Mangat

IDataCursor pipelineCursor = pipeline.getCursor();
String key = IDataUtil.getString( pipelineCursor, “key” );
String value = IDataUtil.getString( pipelineCursor, “value” );
String str = new String();
try{
int check=0;
while(check == 0)
{
check=1;

str = “path for propertyfile”;
Properties pro = new Properties();
File f = new File(str);
if(!f.exists())
{
check=0;
throw new ServiceException(“File not found”);
}
else
{
FileInputStream in = new FileInputStream(f);
pro.load(in);
pro.setProperty(key, value);
pro.store(new FileOutputStream(str),null);
}
}
}
catch(IOException e){
throw new ServiceException("Error reading “+str+” property file: "+e);
}
pipelineCursor.destroy();