properties file

HiI am trying to make a property file using notepad. But it's showing the type to be .txt and not .properties.Do i have to do anyting else after saving it as a .properties file?Message was edited by: Black.Java
[246 byte] By [Black.Javaa] at [2007-11-27 5:40:47]
# 1
Go to File-Save As and give the file name in Quotes as "MyProperties.properties"
Satish_Patila at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 2
Thank you Mr Patil
Black.Javaa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 3

HI

I tried to run the following code. But it gave the error message that

"Can't find bundle for base name MessageBundle, locale en_US"

import java.util.*;

import java.text.*;

public class MessageFormatDemo {

static void displayMessage(Locale currentLocale) {

System.out.println("currentLocale = " + currentLocale.toString());

System.out.println();

ResourceBundle messages =

ResourceBundle.getBundle("MessageBundle",currentLocale);

Object[] messageArguments = {

messages.getString("planet"),

new Integer(7),

new Date()

};

MessageFormat formatter = new MessageFormat("");

formatter.setLocale(currentLocale);

formatter.applyPattern(messages.getString("template"));

String output = formatter.format(messageArguments);

System.out.println(output);

}

static public void main(String[] args) {

displayMessage(new Locale("en", "US"));

System.out.println();

displayMessage(new Locale("de", "DE"));

}

}

properties file:

# MessageBundle.properties_en_US

planet = Mars

template = At {2,time,short} on {2,date,long}, we detected \

{1,number,integer} spaceships on the planet {0}.

Black.Javaa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 4

># MessageBundle.properties_en_US

Is it your file name?

No, you have to name it like that :

<file-name>_<language_code>_<contry-code>.properties

then your name have to be named: MessageBundle_en_US.properties not MessageBundle.properties_en_US

Good Luck

Ahmad Elsafty

NourElsaftya at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 5
I have given the right name: MessageBundle_en_US.properties .But i am getting the same error message?For your information i am working with netbeans.Message was edited by: Black.Java
Black.Javaa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 6

you have to specify you complete bundle package path:

for example if your MessageBundle_en_US.properties file resides in the package com.example, you will write that:

ResourceBundle messages =

ResourceBundle.getBundle("com.example.MessageBundle",currentLocale);

Good Luck

Ahmad Elsafty

NourElsaftya at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 7
HII gave the full package name along with the name of the properties file.Even then i am getting the same type of error message.Please note that i am working with netbeans.
Black.Javaa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 8
Can anyone please help me out?
Black.Javaa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 9

> I gave the full package name along with the name of the properties file.

> Even then i am getting the same type of error message.

Did you put the properties file in your classpath? It has to go in just the same location as a class of the same name would.

> Please note that i am working with netbeans.

That doesn't excuse you from learning about classpaths.

DrClapa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 10
Can u please explain me how to set classpath...?my properties file is in the same package as the main class.
Black.Javaa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 11
>I have given the right name: MessageBundle_en_US.properties .>But i am getting the same error message?I am having the same problem.Is there a solution?
iozturka at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 12
If you have the same problem as above, the solution which also appears above continues to apply.
ejpa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 13
unfortunately it didnt work as it didnt work for blackjava
iozturka at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...
# 14
Fortunately it does work for me. blackjava must have done something wrong, and so must you. Without further information from either of you it is impossible to comment further.
ejpa at 2007-7-12 15:17:34 > top of Java-index,Java Essentials,New To Java...