开发者

ByteArrayOutputStream from OutputStream

How to create OutputS开发者_Python百科tream from ByteArrayOutputStream in Java


Following runs without error:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
OutputStream outStream = stream;

If you see the docs for ByteArrayOutputStream you will find that it extends OutputStream.


ByteArrayOutputStream is a subclass of OutputStream.

ByteArrayOutputStream bos = ...;
OutputStream os = bos;


A ByteArrayOutputStream is an OutputStream. I.e. you can just assign it like this:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream out = baos;


You can create a helper method like follows:

public OutputStream convert(ByteArrayOutputStream arrayOutputStreamParam){
        return arrayOutputStreamParam;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜