java中byte,String,InputStream之间的转换

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入

  * @param in InputStream

  * @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();

  }

  /**

  * 将byte数组转换成InputStream

  * @param in

  * @return

  * @throws Exception

  */

  public static InputStream byteTOInputStream(byte[] in) throws Exception{

  ByteArrayInputStream is = new ByteArrayInputStream(in);

  return is;

  }

  /**

  * 将byte数组转换成String

  * @param in

  * @return

  * @throws Exception

  */

  public static String byteTOString(byte[] in) throws Exception{

  InputStream is = byteTOInputStream(in);

  return InputStreamTOString(is);

  }

  }

[1][2]

你不勇敢,没人替你坚强!

java中byte,String,InputStream之间的转换

相关文章:

你感兴趣的文章:

标签云: