A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yangshang1 中级黑马   /  2012-4-4 08:06  /  2641 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

怎么才能彻底修改系统的默认编码呢

5 个回复

倒序浏览
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Properties;
import java.util.Set;


public class TestProperties {

        /**
         * @param args
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
                // TODO Auto-generated method stub
      //  Properties p=System.getProperties();
      //  p.setProperty("file.encoding","ISO8859-1");//------------>代码1
       // p.setProperty("sun.jnu.encoding","");
        System.out.println(Charset.defaultCharset());   
        
        System.getProperties().put("file.encoding", "iso8859-1");   
      //  System.getProperties().list(System.out);   
                  
        System.out.println(Charset.defaultCharset());  

        System.out.println(Charset.defaultCharset());
               
        System.getProperties().put("file.encoding", "iso8859-1");
        //System.getProperties().list(System.out);
               
        System.out.println(Charset.defaultCharset());  

//        Set s=p.keySet();
//        for(Object o:s)
//        {
//                Object ss=p.get(o);
//                System.out.println(o+"="+ss);
//        }
//                String str ="中国";              
//               String cha=Charset.defaultCharset().name();
//                System.out.println(cha);
//                byte [] buf = str.getBytes();
//
//               
//                for(int i = 0;i < buf.length;i++)
//                       System.out.println(Integer.toHexString(buf[i]));
//
//               
//
//               for(int i = 0 ;i < buf.length;i++)
//                      System.out.write(buf[i]);
//
//
//               System.out.println();
     
        }

}

我的源码
回复 使用道具 举报
学习了!~
回复 使用道具 举报
我运行这代码,怎么输出了4个GBK呀?
回复 使用道具 举报
所以无法彻底修改系统默认编码
回复 使用道具 举报
  我一般都是到Myeclipse下搞好了编码,在写的代码。一般改的地方有2个地方。右击项目名点击Peoperties在resource,有个other可以修改。然后是window-Preferences-Content Types-Text-java Source file里面可以修改.如果都修改了还是代码乱码的话,可以进行转码。如果在做WEB项目的话,可以到tomcat下配置文件下改好编码,在就可以用spring的自带的过滤器改编码。其实只要统一好了编码,其实出现乱码很少。就是出现了,什么情况,就有什么解决方法。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马