File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read properties file from web.xml or through java

 
arun kumar bv
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I have a java web app. I want to specify the path in config.properties file is as shown below:

PhotoFileDir="C:\\appname\photos\\";
HoroscopeFileDir="C:\\appname\horoscope\\";

when i run the application it is showing filenot found exception my java code is like this:

public class ConfigLoader {

public String Uploadphotokey="PhotoFileDir";
public String Uploadhoroscopekey="HoroscopeFileDir";
private static Properties prop =new Properties();

public String getProperty(String key){
if(prop!=null){
ConfigLoader config =new ConfigLoader();
System.out.println("inside configureloader if control******************");
config.loadProperty();
}

return prop.getProperty(key);
}
private void loadProperty(){
FileInputStream inStream;
Properties prop =new Properties();

try {
System.out.println("loading successfully");
inStream = (FileInputStream) getClass().getResourceAsStream("config.properties");

prop.load(inStream);

inStream.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {

e.printStackTrace();
}

public static void main(String[] args) {
File photofile = new File(FileFolder);
FileOutputStream fout1 = new FileOutputStream(photofile);

fout1.write(photobytes);
fout1.flush();
fout1.close();
}
}
can anybody please help me how to read this config.properties through web.xml or from java code or any means.
thanks in advance

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic