This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am relatively a beginner and want to know these java secrets; While going through one famous program called connection pool by Carl Moss I came to read following lines; ----------------------------------------------- package javaservlets.jdbc; import java.sql.*; /** * <p>This class serves as a JDBC connection repository. Since * creating database connections is one of the most time * intensive aspects of JDBC, we'll create a pool of connections. * Each connection can be used and then replaced back into the * pool. * * <p>A properties file 'ConnectionPool.cfg' will be used to * specify the types of JDBC connections to create, as well as * the minimum and maximum size of the pool. The format of * the configuration file is: * * #(comment) * JDBCDriver=<JDBC driver name> * JDBCConnectionURL=<JDBC Connection URL> * ConnectionPoolSize=<minimum size of the pool> * ConnectionPoolMax=<maximum size of the pool, or -1 for none> * ConnectionUseCount=<maximum usage count for one connection> * ConnectionTimeout=<maximum idle lifetime (in minutes) of * a connection> * <other property for JDBC connection>=<value> * * <p>Any number of additional properties may be given (such * as username and password) as required by the JDBC driver. * */ ------------------------------------------------- just these comments are there in the program and .cfg files are got created and there we can include the properties information as we want. It's a wonder for me how such file can be created and java program could automatically read that. I want to create a similar file.Any body could explain with an example and to give reference. I also want to make this .cfg files read only. I also want to make my program output to come on full screen when program is executing.(in Windows) Please give reply to my innocent querries.
ANUJI I'm not familiar with that program but it looks like the cfg file is an xml document that the connection pool program reads before creating the connections. If that is the case, then to do something similar, you'd need to specify the format of the xml file (with a dtd) and then write the code to parse the file when the application starts up. hope that helps
The best way to create a standard property file is using the Properties class. There you have the possibility to add a set of Key - Value pairs. If your set is ready you can store it using a FileOutputStream. The only problem I know is, that you are not able to store comments over this method. If you load a properties file wit comments into the Properties class to change something then all the comments will disappear after saving it. Hope this helps Rene