ByteArrayInputStream和ByteArrayOutputStream
Posted woqiaoxun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ByteArrayInputStream和ByteArrayOutputStream相关的知识,希望对你有一定的参考价值。
public class ByteArrayTest { public static void main(String[] args) throws IOException { read(write()); } //read public static void read(byte[] b) throws IOException{ InputStream is = new BufferedInputStream(new ByteArrayInputStream(b)); byte fush[] = new byte[1024]; int len = 0; while((len=is.read(fush))!=-1){ System.out.println(new String(fush, 0,len)); } is.close(); } //write public static byte[] write() throws IOException{ String s = "what the fuck write"; byte[] b = s.getBytes(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int len=b.length; out.write(b, 0, len); byte[] bytes = out.toByteArray(); out.close(); return bytes; } }
以上是关于ByteArrayInputStream和ByteArrayOutputStream的主要内容,如果未能解决你的问题,请参考以下文章
ByteArrayInputStream和ByteArrayOutputStream
Java 流(Stream)文件(File)和IO -- Java ByteArrayInputStream类