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 =…
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 =…
1.将File.FileInputStream 转换为byte数组: File file = new File("file.txt"); InputStream input = new FileInputStream(file); byte[] byt = new byte[input.available()]; input.read(byt); 2.将byte数组转换为InputStream: byte[] byt = new byte[1024]; InputStream inpu…
1.将File.FileInputStream 转换为byte数组: File file = new File("test.txt"); InputStream input = new FileInputStream(file); byte[] byt = new byte[input.available()]; input.read(byt); 2.将byte数组转换为InputStream: byte[] byt = new byte[1024]; InputStream inpu…