Created
October 16, 2014 06:36
-
-
Save smallnewer/23aa1c06747dfaa1d2b8 to your computer and use it in GitHub Desktop.
把byte[]转换为字符串,try/catch太恶心了
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 把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