How much does the system variable file.encoding affect Java operations? (EXT) Good

Source: Internet
Author: User

This topic from: Nutz's issue 361

In considering this issue, I have always tended to use the system variable file.encoding to change the JVM's default encoding.

Today, I think about how much this system variable affects the JVM. I use the simplest method to look at the effect of this variable-in the Src.zip file of the JDK 1.6.0_20, find the file that contains the file.encoding word. A total of 4 were found, namely: First plays Java.nio.Charset class:

    Public Static CharsetDefaultcharset() { If (Defaultcharset== Null) { Synchronized (Charset.Class) {Java.Security.PrivilegedactionPa= New Getpropertyaction("File.encoding"); StringCsn= (String)Accesscontroller.Doprivileged(Pa); CharsetCs= Lookup (csn if  (cs != Span class= "KWD" >null)  Defaultcharset = CS  else Defaultcharset =} } return;                /span>             

Java.net.URLEncoder static construction method, which affects the method Java.net.URLEncoder.encode (String)

    Static {Dontneedencoding= New BitSet(256); IntI; For (I= A;I< = ' Z ';I++) {Dontneedencoding.Set(I); } For (I= A;I<= Z;I++) {Dontneedencoding.Set(I); } For (I= ' 0 ';I<= ' 9 ';I++) {Dontneedencoding.Set(I); }Dontneedencoding.Set(‘ ‘); /* Encoding a space to A + is do * in the Encode () method */Dontneedencoding.Set(‘-‘);Dontneedencoding.Set(‘_‘); Dontneedencoding. Dontneedencoding. ' * '  Dfltencname   (string)  Accesscontroller. doprivileged  ( new  Getpropertyaction ( "file.encoding"  Span class= "pun");  }            /span>             

Com.sun.org.apache.xml.internal.serializer.Encoding method of Getmimeencoding (209 lines)

    Static StringGetmimeencoding(StringEncoding) { If (Null ==Encoding) { Try { Get the default system character encoding. This May Incorrect if they passed in a writer, but right now there Seems to is no-to-get the encoding from a writer.Encoding= System.GetProperty("File.encoding", "UTF8"); If (Null !=Encoding) { /* * See if the MIME type was equal to UTF8. If you don ' t * does that and then convertjava2mimeencoding'll convert * 8859_1 to "iso-8859-1", which is not the what we want, * I think, and I don ' t think I want to alter the tables * to convert everything to UTF-8. */ StringJencoding= (Encoding.Equalsignorecase("Cp1252") ||Encoding.Equalsignorecase("Iso8859_1") ||Encoding.Equalsignorecase("8859_1") ||Encoding.Equalsignorecase("UTF8")) ?Default_mime_encoding:Convertjava2mimeencoding(Encoding);Encoding= (Null !=Jencoding) ?Jencoding: Default_mime_encoding;} else {= Default_mime_encoding; } } catch Span class= "pun" > (securityexception Se Span class= "pun" >{ encoding = Default_mime_encoding } }       /span>                

The static construction method of the last Javax.print.DocFlavor class:

  static {=  (string ) java.. Accesscontroller. Doprivileged new Sunsecurity.. Getpropertyaction "file.encoding"  Span class= "pun" >               

As you can see, the system variable file.encoding affects
1. Charset.defaultcharset () The most critical encoding settings in the Java environment
2. Urlencoder.encode (String) The most commonly encountered encoding used in a Web environment
3. Com.sun.org.apache.xml.internal.serializer.Encoding affects the reading of XML files without encoding settings
4. Javax.print.DocFlavor the encoding that affects printing

Therefore, the impact is still very large, oh, can be said to be a key code in Java!
Http://wendal.net/232.html


How much does the system variable file.encoding affect Java operations? (EXT) Good

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.