1.字节数组输入流
package com.file;
//字节数组输出流
import java.io.ByteArrayInputStream;
public class ByteArrayInputDemo {
public static void main(String[] args) throws Exception{
byte[] arr="abchgsdjah".getBytes();
ByteArrayInputStream bi=new ByteArrayInputStream(arr);
StringBuilder stringBuilder=new StringBuilder();
int emp=0;
while ((emp=bi.read())!=-1){
stringBuilder.append((char)emp);
}
System.out.println(stringBuilder.toString());
if (bi!=null){
bi.close();
}
}
}
2.字节数组输出流
package com.file;
//字节数组输出流
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class ByteArrayOutputDemo {
public static void main(String[] args) throws IOException {
ByteArrayOutputStream bo=new ByteArrayOutputStream();
bo.write('a');
bo.write('b');
bo.write('c');
byte[] bytes = bo.toByteArray();
for (byte c:
bytes) {
System.out.println((char)c);
}
if (bo!=null){
bo.close();
}
}
}