(转)java中outputStream与inputStream的相互转换import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class ConvertUtil {
// inputStream转outputStream
public ByteArrayOutputStream parse(final InputStream in) throws Exception {
final ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
int ch;
while ((ch = in.read()) != -1) {
swapStream.write(ch);
output的反义词
}
return swapStream;
}
// outputStream转inputStream
public ByteArrayInputStream parse(final OutputStream out) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = (ByteArrayOutputStream) out;
final ByteArrayInputStream swapStream = new ByteArray());
return swapStream;
}
// inputStream转String
public String parse_String(final InputStream in) throws Exception {
final ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
int ch;
while ((ch = in.read()) != -1) {
swapStream.write(ch);
}
String();
}
// OutputStream 转String
public String parse_String(final OutputStream out) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = (ByteArrayOutputStream) out;
final ByteArrayInputStream swapStream = new ByteArray());
String();
}
// String转inputStream
public ByteArrayInputStream parse_inputStream(final String in) throws Exception {
final ByteArrayInputStream input = new Bytes());
return input;
}
// String 转outputStream
public ByteArrayOutputStream parse_outputStream(final String in) throws Exception {
return parse(parse_inputStream(in));
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论