InputStream与byte[]数组相互转换

                //InputSteam转byte[]数组,网上写的会丢失数据。mysql

                byte[] byt = new byte[1024];sql

try {
Runtime rt = Runtime.getRuntime();
// 调用 调用mysql的安装目录的命令
Process child = rt
.exec("F:\\mysql-5.7.20-winx64\\bin\\mysqldump -h localhost -uroot -proot ceshixxxxx");


// 把进程执行中的控制台输出信息写入.sql文件,即生成了备份文件。注:若是不对控制台信息进行读出,则会致使进程堵塞没法运行
InputStream in = child.getInputStream();// 控制台的输出信息做为输入流
//此处开始转换
ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); 
byte[] buff = new byte[1024]; //buff用于存放循环读取的临时数据 
int rc = 0; 
while ((rc = in.read(buff, 0, 1024)) > 0) { 
swapStream.write(buff, 0, rc); 

byt = swapStream.toByteArray(); //in_b为转换以后的结果 
} catch (Exception e) {
e.printStackTrace();

}数组

                //byte[]数据转InputStream
spa

                InputStream inputStream = new ByteArrayInputStream(file);
进程