This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes loading properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "loading properties file" Watch "loading properties file" New topic
Author

loading properties file

Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 288

Hi all

I have a properties file with more then 1000+ key and values

but some time some keys and its values are not loading in to memory

for Example "34545_NameExit=Name already exist"

Please help me what can go wrong


-Chiru
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
How do you retrieve the values? Could you please paste that piece of code?


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 288


Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
How come you're using URL, are you accessing the file over the network? With the constructor that you're using, with the stream, the file must be encoded in ISO-8859-1, can you check if it is?
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 288

the file must be encoded in ISO-8859-1, can you check if it is?


If this is the problem why only one key value pair is not loading ?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Chiranjeevi Kanthraj wrote:but some time some keys and its values are not loading in to memory

How do you know that? Do you get error messages? Do the same key-value pairs really not load sometimes, but correctly other times (that would be very strange)? Can you show us the code that you're using to lookup values?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
I can't reproduce your error. I've tried long properties files, different encodings, ... I always get all keys, including '34545_NameExit' by using

Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 288

Jesper Young wrote:
How do you know that? Do you get error messages? Do the same key-value pairs really not load sometimes, but correctly other times (that would be very strange)? Can you show us the code that you're using to lookup values?


Ok if its duplicate key its should reproduce every time for the same key. but its not happening for same key
Mukesh Ranjan
Greenhorn

Joined: Jun 24, 2009
Posts: 22
why don't you try fileinputstream instead of URL and if you are using URL , which class you are using,

Below code also works, you can use that also where i have used FileInputStream class

try {
URL url = new URL("D://a.txt");
ResourceBundle b = new PropertyResourceBundle(url.openStream());
System.out.println(b.getString("34545_NameExit"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading properties file
 
Similar Threads
Will the Resource Bundle object loads property file into memory?
getting the value of .properties file
Properties file v/s Constants in Java
properties v/s constants
loading properties file