package gov.zhbs.utils;
import java.io.*;
public class aaaa {
// java 输出流转化为输入流
//new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
/**
* 输入流转byte[ ]
*
* @param inStream
* @return
* @throws IOException
*/
private static final byte[] input2byte(InputStream inStream)
throws IOException {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in2b = swapStream.toByteArray();
return in2b;
}
/**
* @param 字节数组,输出文件流 转file对象
* @param outputFile
* @return
*/
public static File writeBytesToFile(byte[] b, String outputFile) {
File file = null;
FileOutputStream os = null;
try {
file = new File(outputFile);
os = new FileOutputStream(file);
os.write(b);
} catch (Exception var13) {
var13.printStackTrace();
} finally {
try {
if (os != null) {
os.close();
}
} catch (IOException var12) {
var12.printStackTrace();
}
}
return file;
}
// outputStream转inputStream
public static ByteArrayInputStream parse(OutputStream out) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = (ByteArrayOutputStream) out;
ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());
return swapStream;
}
}
java 输出流转化为输入流
最新推荐文章于 2024-06-13 13:32:01 发布