JVM Default Character Set problem __JVM

Source: Internet
Author: User
Get JVM Default Character set: System.getproperty ("file.encoding")
public class Test {public
	static void Main (string[] args) {
		System.out.println (System.getproperty (" File.encoding "));
	}
Get different lengths of Chinese characters
public class Test {public
	static void Main (string[] args) {
		System.out.println ("Test". GetBytes (Charset.forname (" UTF-8). length);//Result: 3 System.out.println ("
		test". GetBytes (Charset.forname ("GBK")). length);//Result: 2
	}
}
Through the above tests to draw a general result: XP system installation Tomcat get the default character set for Gbk,linux depending on the language different from the general system porting from under Windows easily garbled (test method can create a new charset.jsp, add the following content).
<%=system.getproperty ("file.encoding")%>
There are two ways to unify the JVM character set: One is to use a uniform character set, such as GetBytes ("GBK"), and so on, when the character set is required, and the second, to specify the java_opts parameter during tomcat startup-dfile.encoding =utf-8 "
java_opts= "$JAVA _opts-dfile.encoding=utf-8"


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.