# Property 2 « PropertyFile « Java I/O Q&A

### 1. edit properties file    coderanch.com

Read 'em all in and write 'em all out is how the Properties class works. It's designed for use with small local files with values that change infrequently, so there's little inefficiency. If you really need random access you could try java.io.RandomAccessFile. Jules [ August 12, 2004: Message edited by: Julian Kennedy ]

### 2. Read from properties file    coderanch.com

Hi, I need to know how to read some values of certain keys from the properties file. this is possible when i tried to do in the Tomcat server but this was not possible when i tried out with the Jboss server. Why is this so?? please do help me out. public class SampleResource { public SampleResource() {} public String callResourcebundle() ...

### 3. Read encrypted string from properties file    coderanch.com

I'm writing a password verification utility. I want to create a properties file with all users and their passwords in name/value pairs, such as user1=password1, where password is encrypted with 3DES. I added following entry in the properties file named "users.properties" tom=AAU but when I tried to retireve the encrypted password using following code, Properties users = new Properties(); users.load(new FileInputStream("c://users.properties")); ...

### 4. Properties File?    coderanch.com

Im trying to use Properties for the first time and I am running into an error. Even when I cut and paste the example I get the same error. Here is the code. import java.util.Properties; Properties dbProperties = new Properties(); dbProperties.load(new FileInputStream("MyConnections.properties")); Error = Syntax error on token(s);misplaced constructor Sysntax error on load = expected after this token These are ...

### 5. wt is Properties file    coderanch.com

Properties files are used in numerous places since they allow you to change text attributes without recompiling code. Anytime you see text labels on JSP pages or swing pages for example, such as the "Post A Replay" I see at the top of my page, its a good idea to extract those out to properties files rather than whats referred to ...

### 7. Properties file    coderanch.com

Hi, I want to load a properties file. Below is the code that I have.I have synchronized at the method level?I know this will slow down the performance.How can I set the synchronization at the block level?Can anyone help me out? public synchronized Properties getPropertyFile(String fileName)throws Exception { Properties prop = (Properties) hashMap.get(fileName); if(prop == null){ prop = new Properties(); InputStream ...

### 8. reading Arabic from a properties file    coderanch.com

Hi, When reading Arabic out of a UTF-8 properties file, the Arabic gets garbled. I've seen some postings that indicate that one has to use the String.getBytes method to transform the garbled string into proper Arabic. Has anyone does this, and have a couple of working lines of code? I've played with it, but haven't gotten it to work. Maybe I'm ...

### 12. Property files    coderanch.com

Hi All, We are having some property files in our project. I don't want to do File I/O operation during each method call nor do I want to load the session with these values. So the property file loading was specified in the static block of the class and the values were retrieved. But the problem here is if the property ...

### 13. Best place for .properties file?    coderanch.com

I have some classes packages in a .jar and put in the myApp\WEB-INF\lib folder of TomCat. These classes read a properties file which will be placed under a conf folder. Fo ex., they should read a file "\conf\db.properties" to get some info. When i created a 'conf' folder under the lib directory, the classes does'nt read from there. Should i package ...

### 14. help me with specify properties file please    coderanch.com

hi, i actually want to use a relative path from my application root that is deployed into weblogic i.e. c:\bea\user_projects\scm\scm.war i mean a web application packaged in war file should have WEB-INF (dir) web.xml and my application.properties is in WEB-INF/classes/config/application.properties how can i reference to the application-root not the os root. can u help! danny.

### 15. Where Do I Place The Properties File?    coderanch.com

I am trying to leave out the information, such as driver, url, username, password from the class that gets a connection from a connection pool. I store those information in the dbConnectionProperties.prop file. Am I supposed to put this properties file at the application root? Is the application root the same as the root of the ServletContext? In terms of Tomcat, ...

### 70. Problem in replacing key/value pair in properties file    coderanch.com

Hi Friends, My Problem is : If i replace any value for corresponding key, its replaces fine and the same way , its remove all (#)comment files. How Can i resolve this problem: for Example: The Existing Properties file contains: # comment 1 one = 1 # comment 2 two = 2 After Replacing the key of one #comment 1 # ...

### 71. Modifying Property Files.    coderanch.com

Yes you can use the Properties class to load and store a property file. look at the load and store methods of this class. The properties class is basically a Hashtable and you can put and remove elements from it. The only problem might be that you will lose any comments already in the property file. I believe the Jakarta Commons ...

### 73. Property Files (placement of the file in the environment)    coderanch.com

Properties are treated as files, and so are discovered relative to the CODEBASE, i,e., wherever in the file system the executing class is. What I usually do is bundle all my classes into a JAR file, and then put the properties file wherever I care to in the directory structure of the jar. You can also use the -jar option for ...

### 74. Properties Files    coderanch.com

After many months away I am starting to get back to my Java project, which means I am relearning may things I thought I understood... I have a program that performs a JDBC connection but I don't want to hardcode the IP address or Database drivers, I would like to be able to store several and simply 'activate' the one I'm ...

### 75. properties files, initial directory, etc...    coderanch.com

Hello Everyone! I am having a fair bit of trouble with properties files, namely how to ensure that they are in the same location on various platforms without recompiling. I develop in Windows at work, and on Linux at home, and every time I transfer code, I have to edit my classes and recompile so they have the proper path... example: ...

### 76. Properties file    coderanch.com

Dear, I have properties file that i have to set with new value. But after i set with new value, the size of that properties size is 0kb... This is the codes: import java.util.*; import java.io.*; public class TestUtil { public static void main( String[] args ) { TestUtil a = new TestUtil(); a.setScheduleProperties( "ThreadUserCancel" ); } public synchronized void setScheduleProperties( ...

### 77. Where java.properties file is kept    coderanch.com

I don't intend to alter system properties like os.name, etc. You know how you can specify you java.policy file to setup your security policy? I thought you could do the same with a properties file so that instead of always doing: java -DMyCustomSysProperty=myValue I could just set it once in a file and forget it. Maybe I'm just imagining the whole ...

### 79. properties file    coderanch.com

There are several ways to do this. You could take the name and location of the file as a command line option, or (especially if it isn't your top level class) you could make the name of the file an attribute of the instance of your class. You could also specify the name of a settings file that you will read ...

### 80. Questions about properties files    coderanch.com

Hello, I have two questions about properties files. 1. Is it possible to import a properties file from another properties file? 2. Is it possible to have variables in a properties file as described below in code snippet. Thanks in advance, Julien. Code snippet: var_one=foo var_two=\$var_one bar The second line would then read "foo bar"

### 81. properties file editing    coderanch.com

Hi Paul, tried using the following code: FileInputStream fin = new FileInputStream("foldername.properties"); FileOutputStream fout = new FileOutputStream("foldername.properties"); Properties props = new Properties(); props.load(fin); props.remove("test"); props.store(fout, "removed test"); inside the properties there are a few keys and "test" is one of them, if I set fout to true, it will append the whole properties file below without the removed key. But if ...

### 82. Reading properties file problem    coderanch.com

Dear All, I'm up against one of those irritating classpath problems. Let me explain the scenario: I have an application deployed as a jar file. This application reads a properties file when it fires up. This properties file needs to be placed in a different directory when deployed so that the administrator can edit the properties contained within it. I have ...

### 83. Properties File reading    coderanch.com

Dear Ranchers, I'm doing a project in JSP and MySQL. For the JSP-MySQL connection , I'm now writing the connection statments in each and every time when I want to insert,delete, update of select the database queries. If I change the MySQL root password, it will affect the coding completely.. So Instead of that I want to put properties file to ...

### 84. Reading key/value pairs from a .properties file and creating objects    coderanch.com

Hi all I am trying to read from a .properties file which has key value pairs for Employee's id, first name, last name and age. I tried to use the Property class's .keys()method into an iterator and construct Employee objects. But the keys were stored in a different order than the one which I stored. I have used the keySet() and ...

### 85. system variables in .properties file    coderanch.com

Hi Balasubramanian Chandrasekaran: already i worked with all these. what i want is: - i will store my .properties file in user.home - this above .properties file should have entries to refer system variable's values like: videofolder=%user.home%\video\; audiofolder=%user.dir%\audio\; - ie from my own .properties file i want to access/refer system variables - How can i do this, syntax, sample, please!! Thanks ...

### 86. getting Properties file in MessageBundle    coderanch.com

The getBundle() method will look for the desired resource bundle on the classpath. In this case, since the locale you are passing in is "en_US", and you are using "MessageBundle" for the baseName, it searches the classpath for the file "MessageBundle_en_US.properties". If it can't find that file, it will look for a file name "MessageBundle_en.properties". Finally, if it can't find that ...

### 90. Problem with properties file    coderanch.com

That's going to be hard, and I doubt it can be done automatically. You first would have to find all Properties objects that load from that properties file (already quite hard - sometimes the properties file can be relative, otherwise absolute). Then you have to find all calls to getProperty on those objects and retrieve the property name from those calls. ...

### 91. Replace words in a file by reading a properties file    coderanch.com

hi guys, am working on file which contains the following many lines of data, Message, String1, String2, String3, String4 Now string1, string2, string3, string4 are alphanumeric codes. now i need to read a properties text file which contains the strings associated with these codes. eg. "String1"="Test Message" so i need to parse my file and replace all occurences of codes with ...

### 92. Reading properties file    coderanch.com

Hi, I am setting up very basic web application. the application consists of 2 small applications. 1: web app 2: common app The db related things are being done in common-app (connection, queries, etc - direct JDBC). and this common app is being added to the web app through JAR integration (using eclipse 3.3 include project). I want to keep my ...

### 93. Properties file issue    coderanch.com

Hi, Yes, I am using the following method to write into properties file.Properties props = new Properties(); FileOutputStream fo = null; try { fo = new FileOutputStream("Filename.properties"); //localdest properties file(each time from jsp properties are saved in this file and then this file is passes to the remote server) props.store(fo, "Filename.properties"); but as we know we can't retain comments.To save comments ...

### 94. Different approach to Properties file ?    coderanch.com

Hi , I have a standalone java application which is run by scheduled job. In the application , i have to check for country specific attributes to control the flow of statement. Usually i would create a country specific properties file and load the property file at the start and continue the action. Basically what i have in property file is ...

### 95. Placeholders in property files    coderanch.com

Please could you tell me if a class exists that can take two property files and merge them together using Ant build script style placeholders? E.g.: Dynamic property file: item1.path={environment.start.path}\{location}\item1 item2.path={environment.start.path}\{location}\item2 Placeholder values property file: environment.start.path=MyDevServer location=uk After the placeholders have been expanded, item1.path would be: MyDevServer\uk\item1 item2.path would be: MyDevServer\uk\item2 Thanks

### 96. Retrieve owner property from file or directory    coderanch.com

How is this question related to JSP? Incorrectly writing raw Java code in a JSP file instead of a Java class, and having problems with that Java code doesn't make it a JSP problem. The IO forum would have been more appropriate. Have patience and a moderator may move it sooner or later.

### 97. Can't locate properties file    coderanch.com

package org.apache.xmlrpc.demo.webserver; import java.net.InetAddress; import org.apache.xmlrpc.common.TypeConverterFactoryImpl; import org.apache.xmlrpc.demo.webserver.proxy.impls.AdderImpl; import org.apache.xmlrpc.server.PropertyHandlerMapping; import org.apache.xmlrpc.server.XmlRpcServer; import org.apache.xmlrpc.server.XmlRpcServerConfigImpl; import org.apache.xmlrpc.webserver.WebServer; public class Server { private static final int port = 8080; public static void main(String[] args) throws Exception { WebServer webServer = new WebServer(port); XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer(); PropertyHandlerMapping phm = new PropertyHandlerMapping(); /* Load handler definitions from a property file. * The property file ...

### 99. FileNotFoundException When Trying to Read from a .properties file    coderanch.com

Dear Sirs and Madames, I am trying to read from a properties file message.properties which is in the SAME package as the calling class. However I keep getting the rintime error message java.io.FileNotFoundException: message.properties (The system cannot find the file specified). I have racked my head as to why this could be but to no avail, for the dake of my ...