Address: http://www.cnblogs.com/521shina/archive/2009/03/19/1417204.html
The getresponsebody method of the getmethod class in the httpclient class library returns the byte [] type, which is inconvenient to operate. I want to convert it to the string type.
I checked the information on the Internet. I think it is better to use this method.
Base64encoder ENC = new base64encoder ();
String converted string = enc. encode (byte array );
Reference http://hi.baidu.com/zhaolm/blog/item/397b0808bc6023d362d986f3.html/cmtid/e3a206f43cb6f9e87609d746
But some people say this
Base64encoder is a non-official JDK class. Although it can be found and used in JDK, it cannot be found in API. These two may be used by Sun's insiders. No relevant documents can be found for the classes in the bag starting with sun, so they may all be unofficial classes. It is also reasonable and normal to receive a warning, because Sun may update or delete unofficial classes in the future. We recommend that you do not use it.
Having this disadvantage, it is quite troublesome to import the jar package, so I gave up using it.
So I checked three methods on an English website, which are relatively simple. I have used 3rd types, but it seems no problem at present.
From http://www.javadb.com/convert-byte-to-string
/** * * @author javadb.com */public class Main { /** * Example method for converting a byte to a String. */ public void convertByteToString() { byte b = 65; //Using the static toString method of the Byte class System.out.println(Byte.toString(b)); //Using simple concatenation with an empty String System.out.println(b + ""); //Creating a byte array and passing it to the String constructor System.out.println(new String(new byte[] {b})); } /** * @param args the command line arguments */ public static void main(String[] args) { new Main().convertByteToString(); }}