首页 > 代码库 > 获取assets编码问题

获取assets编码问题

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编码问题