• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Property File

 
meenu teenu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Please can anyone tell how to get the conten from property file.



Thanks in advance
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the load method available on Properties class
 
meenu teenu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone help with the code to get the contents of ".properties" file.
 
meenu teenu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone help with the code to get the contents of ".properties" file.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you've loaded the properties file, you can get a specific property with the getProperty(String) method. You can also call this in a loop by getting the property names and iterating through them. Or you can write the Properties out to an output stream. All the methods are in the JavaDocs Jaikiran Pai pointed you at.

What have you tried so far and what is not working?
 
Ravissant Markenday
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code for retrieving a property "message" from the properties file message.properties:

import java.io.*;
import java.util.*;

public class Greeting2
{
String message;

// class constructor

public Greeting2()
{

}

public void setMessage()
{

//create an instance of properties class

Properties props = new Properties();

//try retrieve data from file


try {

props.load(new FileInputStream("message.properties"));

message = props.getProperty("message");

System.out.println(message);
}

//catch exception in case properties file does not exist

catch(IOException e)
{
e.printStackTrace();
}
}

public static void main(String[] args)
{
//create an instance of greeting2 class

Greeting2 gr = new Greeting2();

//call the setMessage() method of the Greeting2 class

gr.setMessage();

}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic