cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the properties file available in Server File structure in webdy

former_member192283
Participant
0 Kudos

hi all,

I have developed one webdynpro application. In this application i need to access mdm server to continue. For getting the connection i need to pass the IP addresses.

Can i have code how to read the properties file which is residing in the server file. with out included along with the application. keeping some where in the file structure in the server. I want to read that properties file by maintain the iP addresses and users in properties file based on the key i want to read like below.

servername="abcServer"

username="john"

password="test123"

Please send me the code how to read this properties file from the file structure and how to read this values by key in webdynpro application

Regards

Vijay

Accepted Solutions (0)

Answers (4)

Answers (4)

nikhil_bose
Active Contributor
0 Kudos

plz go through [this thread|] and [using URL generator|]

Former Member
0 Kudos

Hi Vijay,

You can try this piece of code too:

Properties props = new Properties();

//try retrieve data from file
//catch exception in case properties file does not exist
try {
         props.load(new FileInputStream("c:\property\Test.properties")); //File location
         String serverName = props.getProperty("servername"); //Similarly, you can access the other properties 
         
         if(serverName==null)
         {
           //....do appropriate handling
         }
         
     }	catch(IOException e)
        {
     	     e.printStackTrace();
        }

Regards,

Alka.

Former Member
0 Kudos

Oh please, reading Filesystems with java.io is not allowed within an application server context!

nikhil_bose
Active Contributor
0 Kudos

vijay,

you can use Pavels' code if it is in same server. or if you want a file from server file system, go for [java.io.File|http://java.sun.com/j2se/1.3/docs/api/java/io/File.html].

if the file needs to be a part of application, put it in \src\package\mimes\ folder.

let me know if this is not what you looking for

nikhil

Former Member
0 Kudos

Hello, Vijay Krishna Meda!

Please consider following code.


final String servername;
final String username;
final String password;

try {
  final IWDConfiguration configuration =
    WDConfiguration.getConfigurationByName(
      wdComponentAPI.getDeployableObjectPart(),
      "Connection"); // Name of configuration file without ".properties"

  servername = configuration.getStringEntry("servername");
  username = configuration.getStringEntry("username");
  password = configuration.getStringEntry("password");
} catch (WDConfigurationNotFoundException e) {
// Configuration not found
} catch (WDInvalidConfigParameterException e) {
// Invalid parameter
}