Android中检测字符编码(GB2312,ASCII,UTF8,UNICODE,TOTAL——ENCODINGS)方法(二)
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)方法(二)的更多相关文章
- Android中检测字符编码(GB2312,ASCII,UTF8,UNICODE,TOTAL——ENCODINGS)方法(一)
package com.android.filebrowser; import java.io.*; import java.net.*; public class FileEncodingD ...
- 转载:字符编码简介 ASCII UTF-8 ISO8859-1
字符编码简介 ASCII UTF-8 ISO8859-1 博客分类: 电脑综合知识 XP数据结构Windows 计算机中的一切都是以数字来表示的,字符同样如此.字符编码就是将字符集编码成为数字序列, ...
- 三种字符编码:ASCII、Unicode和UTF-8
原文:三种字符编码:ASCII.Unicode和UTF-8 什么是字符编码? 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字 ...
- 中文乱码之《字符编码:ASCII,Unicode 和 UTF-8》
参考文献:字符编码笔记:ASCII,Unicode 和 UTF-8 一.ASCII 码 我们知道,计算机内部,所有信息最终都是一个二进制值.每一个二进制位(bit)有0和1两种状态,因此八个二进制位就 ...
- 字符编码:ASCII,Unicode和UTF-8
字符编码是计算机技术的基石,想要熟练使用计算机,就必须懂得一点字符编码的知识. 1. ASCII码 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两 ...
- 三种常见字符编码:ASCII、Unicode和UTF-8
什么是字符编码? 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节(byte),所以,一个字节能表示的最大的整数就是255( ...
- 关于字符编码:ascii、unicode与utf-8
转自:https://foofish.net/unicode_utf-8.html 阮一峰老师对普及计算机基础技术功不可没,但毕竟老师不是神,因此也避免不了对某些概念有一些错误的理解,<字符编码 ...
- 字符编码,ASCII、Unicode与UTF-8的理解
首先我们先要明白的两点是:1.计算机中的信息都是由二进制的0和1储存的:2.我们再计算机屏幕上看到的各种字符都是计算机系统按照一定的规则将二进制数字转换而来的. 一.基本概念. 1.字符集(chars ...
- 字符编码方式ASCII、Unicode、UTF-8
一.ASCII 1.介绍 即American Standard Code for Information Interchange(美国信息交换标准代码),是基于拉丁字母的,主要用于显示现代英语和其他西 ...
随机推荐
- python 二进制数相加
def add_binary_nums(x,y): max_len = max(len(x), len(y)) x = x.zfill(max_len) y = y.zfill(max_len) re ...
- ubuntu 14.04 安装 gflags
1.下载 git clone https://github.com/gflags/gflags 2.编译 进入源码目录(即gflags文件夹) cmake . make -j 24 sudo make ...
- spring boot 开发 ajax返回值报错
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "succeed", templ ...
- Codeforces 909C - Python Indentation
909C - Python Indentation 思路:dp. http://www.cnblogs.com/Leohh/p/8135525.html 可以参考一下这个博客,我的dp是反过来的,这样 ...
- Codeforces 832D - Misha, Grisha and Underground
832D - Misha, Grisha and Underground 思路:lca,求两个最短路的公共长度.公共长度公式为(d(a,b)+d(b,c)-d(a,c))/2. 代码: #includ ...
- English trip -- Phonics 5 元音字母 o
Vowel 元音 元音 O Consonant 辅音 清辅音 h wh 浊辅音 m wh n ng y oa:[əʊ] # 字母本身音 coat boat load co ...
- alias和alias_method的区别:
1.alias 是 Ruby 的一个关键字,因此使用的时候是 alias :new name :oldname,而 alias_method 是 module 类的一个方法,因此使用的时候是 alia ...
- android--------Retrofit+RxJava的使用
Retrofit是Square公司开发的一款针对Android网络请求的一个当前很流行的网络请求库. http://square.github.io/retrofit/ https://github. ...
- array_unshift
<!DOCTYPE html> <html> <body> <?php $a=array(0=>"red",1=>" ...
- FastDFS install
Version: os: centos7 x64 FastDFS: 5.05 libfastcommon: latest 1. dwonload libfastcommon https://githu ...