aspose file tools*
The moose likes Java in General and the fly likes Property File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Property File" Watch "Property File" New topic
Author

Property File

meenu teenu
Greenhorn

Joined: Dec 05, 2006
Posts: 8
Hi all,

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



Thanks in advance
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

Have a look at the load method available on Properties class


[My Blog] [JavaRanch Journal]
meenu teenu
Greenhorn

Joined: Dec 05, 2006
Posts: 8
Hi,

Can anyone help with the code to get the contents of ".properties" file.
meenu teenu
Greenhorn

Joined: Dec 05, 2006
Posts: 8
Hi,

Can anyone help with the code to get the contents of ".properties" file.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ravissant Markenday
Ranch Hand

Joined: Nov 12, 2006
Posts: 47
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();

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Property File