java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow java.util arrow How to read and write a Properties file
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4094
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to read and write a Properties file E-mail
User Rating: / 204
PoorBest 

This Java tip illustrates a method of reading and writing a Properties file. Developer may read by using input stream and write by using output stream.

Here is an example of the contents of a properties file:

    # a comment
    ! a comment
    
    a = a string
    b = a string with escape sequences \t \n \r \\ \" \' \ (space) \u0123
    c = a string with a continuation line \
        continuation line
    d.e.f = another string
    // Read properties file.
    Properties prop = new Properties();

    try {
        prop.load(new FileInputStream("filename.properties"));
    catch (IOException e) {
    }
    
    // Write properties file.
    try {
        prop.store(new FileOutputStream("filename.properties")null);
    catch (IOException e) {
    }


 Related Tips

 
< Prev   Next >
 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.