首页 > 其他 > 详细

获取assets编码问题

时间:2014-09-23 13:12:56      阅读:288      评论:0      收藏:0      [点我收藏+]
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;

	}

 

获取assets编码问题

原文:http://www.cnblogs.com/mengxq/p/3987977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!