标签:blog io ar 文件 div sp 问题 on c
public String read(String fileName) {
String reultString = "";
try {
InputStream in = getResources().getAssets().open(fileName);
int available = in.available();
byte[] byte1 = new byte[available];
in.read(byte1);
String sssString=codetype(byte1);
reultString = EncodingUtils.getString(byte1, sssString);
Log.i("ABC", sssString+"---?---");
// reultString = new String(byte1, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
return reultString;
}
// 获取文件的编码格式
public String codetype(byte[] head) {
String code = "";
if (head[0] == -1 && head[1] == -2) {
code = "UTF-16";
} else if (head[0] == -2 && head[1] == -1) {
code = "Unicode";
} else if (head[0] == -17 && head[1] == -69 && head[2] == -65)
code = "UTF-8";
else {
code = "gb2312";
}
return code;
}
标签:blog io ar 文件 div sp 问题 on c
原文地址:http://www.cnblogs.com/mengxq/p/3987977.html