byte[]和InputStream的相互转换[转载]】的更多相关文章

1:byte[]转换为InputStream InputStream sbs = new ByteArrayInputStream(byte[] buf); 2:InputStream转换为InputStreambyte[] ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据 int rc = 0; while ((rc =…
1:byte[]转换为InputStream InputStream sbs = new ByteArrayInputStream(byte[] buf); 2:InputStream转换为InputStreambyte[] ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据 int rc = 0; while ((rc =…
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; /** * @see InputStream转化为String String 转换为InputStream InputStream 转化为byte数组 byte转化为InputStream byte转化为String * @author…
File.FileInputStream 转换为byte[] File file = new File("test.txt"); InputStream input = new FileInputStream(file); byte[] bytes = new byte[input.available()]; input.read(bytes); byte[]转换为InputStream byte[] bytes = new byte[1024]; InputStream input…
package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.grap…
package com.boco.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.OutputStream; public class ConvertUtil { //inputStream转outputStream public ByteArrayOutputStream parse(InputS…
char转化为byte: public static byte[] charToByte(char c) {        byte[] b = new byte[2];        b[0] = (byte) ((c & 0xFF00) >> 8);        b[1] = (byte) (c & 0xFF);        return b;    } char[]转化为byte[]: char[] cChar=new char[5]{a,b,c,d,e};  byt…
1.将字符转换成byte数组 String str = "罗长"; byte[] sb = str.getBytes(); 2.将byte数组转换成字符 byte[] b={(byte)0xB8,(byte)0xDF,(byte)0xCB,(byte)0xD9}; String str= new String (b); 3.为了方便字符的加减操作,通常以16进制字符替代普通字符与byte数组进行相互转换 /** * 16进制的字符串表示转成字节数组 * * @param hexStri…
一:inputStream转换 1.inputStream转为byte //方法一 org.apache.commons.io.IOUtils包下的实现(建议) IOUtils.toByteArray(inputStream); //方法二 用java代码实现(其实就是对上面方法一的解析) public static byte[] toByteArray(InputStream input) throws IOException { ByteArrayOutputStream output =…
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.PixelFormat; import…