码迷,mamicode.com
首页 > 移动开发 > 详细

Android中检测字符编码(GB2312,ASCII,UTF8,UNICODE,TOTAL——ENCODINGS)方法(二)

时间:2014-06-08 04:37:56      阅读:425      评论:0      收藏:0      [点我收藏+]

标签:android   c   code   a   ext   int   

Intent intent = getIntent();
        String contentUri = null;
        Uri uri =null;
        if (intent.getData() != null) {
            uri = intent.getData();
            contentUri = "file".equals(uri.getScheme())
                    ? FileContentProvider.BASE_URI + uri.getEncodedPath()
                    : uri.toString();
            String intentType = intent.getType();
            if (intentType != null) {
                contentUri += "?" + intentType;
            }
        }
        File mFile = new File(uri.getPath());
        InputStream mIn = null;
        try{
            Log.d(LOGTAG,"file is "+mFile);
            mIn = new FileInputStream(mFile);
            byte[]b = new byte[3];
            mIn.read(b);
            
            mIn.close();
            Log.d(LOGTAG,"B is "+b[0]+b[1]+b[2]);
            if (b[0]==-27||(b[0]==-17&&b[1]==-69&&b[2]==-65))  {
                s.setDefaultTextEncodingName("utf-8");//added by chenxuan for SWBUG00027593
             }
            else{
                s.setDefaultTextEncodingName("GBK");
                }
         }catch(FileNotFoundException e){
            Toast.makeText(this,R.string.file_inexistence,Toast.LENGTH_SHORT).show();
            finish();
            return;
         }catch(IOException ex){
            finish();
            Toast.makeText(this, R.string.read_file_failed,Toast.LENGTH_SHORT).show();
            return;
        }

Android中检测字符编码(GB2312,ASCII,UTF8,UNICODE,TOTAL——ENCODINGS)方法(二),布布扣,bubuko.com

Android中检测字符编码(GB2312,ASCII,UTF8,UNICODE,TOTAL——ENCODINGS)方法(二)

标签:android   c   code   a   ext   int   

原文地址:http://blog.csdn.net/huangyabin001/article/details/29193981

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!