velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From y...@netpotlet.com
Subject Re: Regd: Japanese characters
Date Thu, 04 Apr 2002 07:05:17 GMT
From: Vanitha.S@lntinfotech.com
Subject: Regd: Japanese characters
Date: Wed, 3 Apr 2002 20:35:54 +0530
Message-ID: <OFD4C6CC6E.4D2ECDDB-ON65256B90.0052B720@lntinfotech.com>

>      I am using velocity for my web application project. Currently i am
> facing a problem when i am reading some contents from a file which contains
> japanese characters and outputting it to a template. The screen comes up
> with junk characters. I tried to debug and find where actually the problem
> is.. Everything seems to be ok until when i send it to the Context object.

Did you specify the encoding of Reader object ?
If not, you should use InputStreamReader before BufferedReader like this:

    FileInputStream istream = new FileInputStream(filename);
    BufferedReader reader = 
        new BufferedReader(new InputStreamReader(istream, 
                                                 "JISAutoDetect"));

JISAutoDetect detects iso-2022-jp, euc-jp and Shift_JIS.
UTF-8 is not detected by JISAutoDetect.

I recommand you to check the String is correct or not by this method.
If the argument is correct Unicode String, return value shuoule be
like this: 3053 3093 306b 3061 306f 4e16 754c

    private String dump(String str) {
	StringBuffer sb = new StringBuffer();
	char[] buf=str.toCharArray();
	sb.append("dump: ");
	for (int i=0; i<buf.length; i++) {
	    sb.append(Integer.toString(buf[i], 16)+" ");
	}
	return new String(sb);
    }

I hope this helps you.

---
Yoko Kamei Harada, Web Studio Ne-Po-Le
http://www.netpotlet.com/

--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message