Comments on: How to Read/Write Java Properties Files http://www.factorypattern.com/how-to-readwrite-java-properties-files/ Just another Object Oriented Weblog Fri, 04 Jun 2010 13:55:21 -0700 http://wordpress.org/?v=2.9.1 hourly 1 By: Ciaran http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-287 Ciaran Thu, 06 May 2010 17:19:57 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-287 After I load the properties from the classpath I'm getting the BOM characters  appended to the start - meaning when I try and use getProperty() for my first property I get null returned - any ideas what I'm doing wrong here?? After I load the properties from the classpath I’m getting the BOM characters  appended to the start – meaning when I try and use getProperty() for my first property I get null returned – any ideas what I’m doing wrong here??

]]>
By: LATESH http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-286 LATESH Tue, 04 May 2010 17:22:05 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-286 import java.io.*; import java.util.*; public class WriteProperty{ String str, key, val; public static void main(String[] args) { WriteProperty w = new WriteProperty(); } public WriteProperty(){ try{ int check=0; while(check == 0){ check=1; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter file name which has properties extension:"); str = bf.readLine(); Properties pro = new Properties(); File f = new File(str + ".properties"); if(!f.exists()){ check=0; System.out.println("File not found!"); } else{ FileInputStream in = new FileInputStream(f); pro.load(in); System.out.print("Enter Key : "); key = bf.readLine(); System.out.print("Enter Value : "); val = bf.readLine(); pro.setProperty(key, val); pro.store(new FileOutputStream(str + ".properties"),null); System.out.println("Operation completly successfuly!"); } } } catch(IOException e){ System.out.println(e.getMessage()); } } } import java.io.*;
import java.util.*;

public class WriteProperty{
String str, key, val;
public static void main(String[] args) {
WriteProperty w = new WriteProperty();
}
public WriteProperty(){
try{
int check=0;
while(check == 0){
check=1;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter file name which has properties extension:”);
str = bf.readLine();
Properties pro = new Properties();
File f = new File(str + “.properties”);
if(!f.exists()){
check=0;
System.out.println(“File not found!”);
}
else{
FileInputStream in = new FileInputStream(f);
pro.load(in);
System.out.print(“Enter Key : “);
key = bf.readLine();
System.out.print(“Enter Value : “);
val = bf.readLine();
pro.setProperty(key, val);
pro.store(new FileOutputStream(str + “.properties”),null);
System.out.println(“Operation completly successfuly!”);
}
}
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
}

]]>
By: Nischal Shetty http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-282 Nischal Shetty Mon, 12 Apr 2010 07:16:32 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-282 Phew! that helped me, thnks a lot :) Phew! that helped me, thnks a lot :)

]]>
By: Kovid http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-279 Kovid Tue, 02 Mar 2010 17:33:04 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-279 I don't understand this. How do I create a .properties file? Its not making sense to me. Thanks in advance, Kovid I don’t understand this. How do I create a .properties file?
Its not making sense to me. Thanks in advance,
Kovid

]]>
By: Sandeep http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-274 Sandeep Wed, 03 Feb 2010 02:57:20 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-274 Thank you very much,it helped me a lot Thank you very much,it helped me a lot

]]>
By: John, the Fisherman http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-271 John, the Fisherman Mon, 11 Jan 2010 04:08:50 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-271 Saved my day! I was having problems trying to load the file using a relative path in my web app. Also, I did not remeber the existence of the Properties class. Saved my day! I was having problems trying to load the file using a relative path in my web app. Also, I did not remeber the existence of the Properties class.

]]>
By: ravil http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-266 ravil Thu, 10 Dec 2009 16:16:55 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-266 Thanks a lot for your brief instructions. The are very helpful!! Thanks a lot for your brief instructions. The are very helpful!!

]]>
By: ranganath http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-265 ranganath Thu, 10 Dec 2009 06:22:20 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-265 read worth. read worth.

]]>
By: nagarajan http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-114 nagarajan Wed, 30 Sep 2009 08:33:40 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-114 finding the path of the property file in web application is explained very well.Thanks! finding the path of the property file in web application is explained very well.Thanks!

]]>
By: admin http://www.factorypattern.com/how-to-readwrite-java-properties-files/comment-page-1/#comment-103 admin Thu, 27 Nov 2008 15:10:34 +0000 http://www.factorypattern.com/how-to-readwrite-java-properties-files/#comment-103 Actually is not possible to write properties files in classpath, because the properties are picked up by jvm and they are read as resources. It's the JVM to control when they are loaded and once loaded they are reloaded. In less words, it's not possible as I know. Of course you can modify the files, but not using them as classpath resources, and you can not use the reading methods I described earlier;l sorry for the misleading title. Initially I intended to put all the read/write methods for property files but I ended putting only those I'm using. Actually is not possible to write properties files in classpath, because the properties are picked up by jvm and they are read as resources. It’s the JVM to control when they are loaded and once loaded they are reloaded. In less words, it’s not possible as I know.

Of course you can modify the files, but not using them as classpath resources, and you can not use the reading methods I described earlier;l sorry for the misleading title.

Initially I intended to put all the read/write methods for property files but I ended putting only those I’m using.

]]>