This code properly reads the unicode files in jsp and set in session

        Properties prop = null;
                        if (session.getAttribute("Properties") == null) {
                                
                                URL myURL = null;
                                
                                myURL = 
application.getResource("/common/language/japanese_lang.properties");
                                
                                
                                String fnsKey;
                                String fnsVal;
                                InputStream is = myURL.openStream();
                                BufferedReader in = new BufferedReader(new 
InputStreamReader(is, "UTF-8"));
                                prop = new Properties();
                                String fnsData;
                                fnsData = in.readLine();
                                while (fnsData != null) {
                                        String fnsRetVal = "";
                                        StringTokenizer stParse = new 
StringTokenizer(fnsData, "="); //breaking the string
                                        while (stParse.hasMoreTokens()) {
                                                fnsKey = 
stParse.nextToken().trim();
                                                if (stParse.hasMoreTokens()) {
                                                        fnsVal = 
stParse.nextToken().trim();
                                                        
prop.setProperty(fnsKey, fnsVal);
                                                }
                                        }
                                        fnsData = in.readLine();
                                }
                                session.setAttribute("Properties", prop);
                        } else {
                                prop = (Properties) 
session.getAttribute("Properties");
                        }



Thanks and Regards,
Kapil Sharma 
IAP Company Ltd.


-----Original Message-----
From: Christopher Schultz [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 09, 2007 7:18 AM
To: Struts Users Mailing List
Subject: Re: [OT] Reading Unicode Files


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott

Mulligan, Scott H wrote:
> In my Struts application, when I load a Resource Bundle (Property file)
> that has Unicode characters (\u1234) they get interpreted as single
> characters. However, when I read a file using a FileInputStream the
> Unicode characters get interpreted as a String "\u1234".

java.util.Properties.load includes the interpretation of those \uWXYZ
codes, while you are probably not reading them in as such.
(ResourceBundle uses Properties.load or something exactly like it to
load PropertyResourceBundles).

> I know I am missing something basic, but I can not figure it out. Can
> anyone please tell me what the Properties.load() method does that I am
> not doing?

They specifically look for \uWXYZ sequences and do their own conversion.
It's not a character encoding issue or anything like that... it's just
parsing and converting. You'll have to do it yourself.

Don't forget that if you have the JDK installed you can look at the Java
sources for just about any class. Try looking for JAVA_HOME/src.zip or
JAVA_HOME/share/src.zip and looking at the java.util.Properties source
code yourself.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQPcZ9CaO5/Lv0PARAsZPAKCGHvlQS0kVFTIJeuEexHQbIZ+iyACeKohv
W0kv/TF72AucxxIwNNQlt4s=
=LCf9
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to