[Html] <pre class = "html" name = "code"> import java. io. byteArrayInputStream; import java. io. byteArrayOutputStream; import java. io. IOException; import java. io. inputStream; public class InputStreamUtils {final static int BUFFER_SIZE = 4096; /*** convert InputStream to String * @ param in InputStream * @ return String * @ throws Exception **/public static String InputStreamTOString (InputStream in) throws into t Ion {ByteArrayOutputStream outStream = new ByteArrayOutputStream (); byte [] data = new byte [BUFFER_SIZE]; int count =-1; while (count = in. read (data, 0, BUFFER_SIZE ))! =-1) outStream. write (data, 0, count); data = null; return new String (outStream. toByteArray (), "ISO-8859-1 ");} /*** convert InputStream to a character-encoded String * @ param in * @ param encoding * @ return * @ throws Exception */public static String InputStreamTOString (InputStream in, string encoding) throws Exception {ByteArrayOutputStream outStream = new ByteArrayOutputStream (); byte [] data = new byte [BUFFER_SIZE]; I Nt count =-1; while (count = in. read (data, 0, BUFFER_SIZE ))! =-1) outStream. write (data, 0, count); data = null; return new String (outStream. toByteArray (), "ISO-8859-1");}/*** convert String to InputStream * @ param in * @ return * @ throws Exception */public static InputStream StringTOInputStream (String in) throws Exception {ByteArrayInputStream is = new ByteArrayInputStream (in. getBytes ("ISO-8859-1"); return is;}/*** converts InputStream to a byte array * @ param in InputStrea M * @ return byte [] * @ throws IOException */public static byte [] InputStreamTOByte (InputStream in) throws IOException {ByteArrayOutputStream outStream = new ByteArrayOutputStream (); byte [] data = new byte [BUFFER_SIZE]; int count =-1; while (count = in. read (data, 0, BUFFER_SIZE ))! =-1) outStream. write (data, 0, count); data = null; return outStream. toByteArray ();}/*** converts the byte array to InputStream * @ param in * @ return * @ throws Exception */public static InputStream byteTOInputStream (byte [] in) throws Exception {ByteArrayInputStream is = new ByteArrayInputStream (in); return is ;} /*** convert byte array to String * @ param in * @ return * @ throws Exception */www.2cto.com public static String byteTOString (byte [] in) throws Exception {InputStream is = byteTOInputStream (in); return InputStreamTOString (is) ;}</pre> <br> <pre> </pre> <br>