• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Property File

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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



Thanks in advance
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can anyone help with the code to get the contents of ".properties" file.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();

}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic