cancel
Showing results for 
Search instead for 
Did you mean: 

Editing Properties files on button

06-27-2011 8:24 AM
180 views 3 comments
0 Likes
SAP Managed Tags
Subscribe

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

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Likes

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 Member
0 Likes

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 Likes

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.