Skip to content

Instantly share code, notes, and snippets.

@smallnewer
Created October 16, 2014 06:36
Show Gist options
  • Save smallnewer/23aa1c06747dfaa1d2b8 to your computer and use it in GitHub Desktop.
Save smallnewer/23aa1c06747dfaa1d2b8 to your computer and use it in GitHub Desktop.
把byte[]转换为字符串,try/catch太恶心了
/**
* 把byte[]转换为字符串
* 转换失败返回null
*/
public String byte2str(byte[] bytes){
String s = null;
try {
s = new String(bytes, "UTF8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment