cancel
Showing results for 
Search instead for 
Did you mean: 

Editing Properties files on button

Former Member
0 Kudos

Hello All,

I have a property file named "Filesystem.properties". entried as follows in it.


Drives = C;D
C = Documents;Program_Files;Temp;Windows;start.bat

I am rendering this structure in a tree UI. I am using the std. Tut_WD_tree component available on SDN. In additon to this, i have a requirement to change the values in properties file if a user selects any value in the tree.

Actually, I have to implement drag & drop functionality and it is possible in CE 7.2 but what I am not getting is how to retrieve the values in this property file and edit it using a java code.

I also referred to this thread but code given at this thread wont work in my case.

Any help or pointers for this?

Ameya

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Below is the snippet to write data into the existing property file,


Properties properties = new Properties();
File propFile = new File("FilePath for propetry file");   
FileInputStream ipStream = null;
FileOutputStream opStream = null;
if(propFile.exists()){
try {
ipStream = new FileInputStream(propFile);
properties.load(ipStream);
properties.put("New Key/Old Key", "New Value");
opStream = new FileOutputStream(propFile);
properties.store(opStream, null);	
wdComponentAPI.getMessageManager().reportSuccess("File updated Successfully");
}
catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(e.toString());
}
finally{
if(null != ipStream ){
ipStream.close();
}
}	  	
}
else{
wdComponentAPI.getMessageManager().reportException("File not Found");
}

Regards,

Vishweshwara P.K.M.

former_member188632
Active Contributor
0 Kudos

Thank you very much for the code just a quick question here, what is the type of "File" here?

Also, i am not able to find this import

import com.sun.java.util.jar.pack.Package.File;

Ameya

Edited by: Ameya Pimpalgaonkar on Jun 27, 2011 8:54 AM

Former Member
0 Kudos

Hi,

"File" is an abstract representation of the property file, stored in the given file path. Its is a IO class and import java.io.File; should be used for that.

Regards,

Vishweshwara P.K.M.