• Post Reply Bookmark Topic Watch Topic
  • New Topic

read a properties file

 
Robin Richardson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm not familiar with reading from a properties file with java.
I need to put info in a static file and have my program read from that file to make connections with a database. Can someone give me an idea how to read that data?
Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Properties java.io.InputStream)" TARGET=_blank rel="nofollow">load() method.
 
Suresh Ray
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use ResourceBundle (java.util.ResourceBundle) to load properties file. Make sure that the properties file is in the classpath.
 
edi kapllani
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;
import java.io.*;
..
class takeProperty {
takeProperty(){
this.initExample();
}
initExample{
try{
Properties Prop = new Properties();
Prop.load(new FileInputStream("c:\\dir1\\file.properties");
String PathImage =Prop.getProperty("ImagePath");
String PathJsp = Prop.getProperty("JspPath");
}catch(IOException ioe){
ioe.printStackTrace();
}
public static void main(){
new takeProperty();
}

}
...
...
file.properties...
# that's contents of file.properties fie
ImagePath=http://edi.space.it/Artco/Images
JspPath=http://edi.space.it/Artco
#
#
...use the above code like a model
ciao!


------------------
 
Robin Richardson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Edi!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!