集册 Java实例教程 将字节数组转换为InputStream

将字节数组转换为InputStream

欢马劈雪     最近更新时间:2020-01-02 10:19:05

570
将字节数组转换为InputStream



import java.io.ByteArrayInputStream;
/**
 * n o w j a v a . c o m - 时代Java 提 供 
**/

import java.io.IOException;

import java.io.InputStream;


public class ByteArrayToInputStream {


    public static final void main(String[] args) {

        String string = "this is a test";

        byte[] content = string.getBytes();

        int size = content.length;

        InputStream is = null;

        byte[] b = new byte[size];


        try {//时 代 J a v a - nowjava.com 提 供

            is = new ByteArrayInputStream(content);

            is.read(b);

            System.out.println(new String(b));

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            if (is != null) {

                try {
展开阅读全文