List of usage examples for java.lang String String
String(byte[] value, byte coder)
From source file:Main.java
public static String fromByteArrayToUtf8String(byte[] bytes) { try {/* w ww .j a v a2 s . c o m*/ return new String(bytes, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getStringFromByte(byte[] bytes) throws UnsupportedEncodingException { return new String(bytes, "UTF-8"); }
From source file:Main.java
public static String byteArraytoString(byte[] byteArray) { try {//from w ww . ja v a2 s .c om if (byteArray != null) { String str = new String(byteArray, "UTF-8"); return str; } else { return ""; } } catch (Exception e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String encodeStr(String str, String srcEncoding, String destEncoding) { String ret = null;// w ww . j a v a2 s . c om try { ret = new String(str.getBytes(srcEncoding), destEncoding); } catch (Exception e) { ret = srcEncoding + " to " + destEncoding + " error. str=" + str; } return (ret); }
From source file:Main.java
public static String utf8Encoding(String value, String sourceCharsetName) { try {/*from ww w.j a va2 s.c o m*/ return new String(value.getBytes(sourceCharsetName), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } }
From source file:Main.java
private static String iso8859togbk(Object obj) { try {//w w w . j a v a2s . co m if (obj == null) return ""; else return new String(obj.toString().getBytes("iso-8859-1"), "GBK"); } catch (Exception e) { return ""; } }
From source file:Main.java
private static String gbktoiso8859(Object obj) { try {// w w w . j a v a2 s. co m if (obj == null) return ""; else return new String(obj.toString().getBytes("GBK"), "iso-8859-1"); } catch (Exception e) { return ""; } }
From source file:Main.java
public static String getEncoding(String str) { String encode = "GB2312"; try {/*from ww w . j a v a 2s. c om*/ if (str.equals(new String(str.getBytes(encode), encode))) { return encode; } } catch (Exception exception) { } encode = "ISO-8859-1"; try { if (str.equals(new String(str.getBytes(encode), encode))) { return encode; } } catch (Exception exception1) { } encode = "UTF-8"; try { if (str.equals(new String(str.getBytes(encode), encode))) { return encode; } } catch (Exception exception2) { } encode = "GBK"; try { if (str.equals(new String(str.getBytes(encode), encode))) { return encode; } } catch (Exception exception3) { } return "GBK"; }
From source file:Main.java
public static String getEntryName(ZipEntry entry) { try {/*from w w w . j av a 2 s .c o m*/ return new String(entry.getName().getBytes("GB2312"), "8859_1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String byte2String(byte[] bytes) { if (bytes == null) { return ""; } else {//from w ww . jav a2 s . c om return new String(bytes, Charset.forName("UTF-8")); } }