It is tedious to send an array of bytes to a ByteArrayOutputStream stream in one method and immediately receive it in a ByteArrayInputStream . I'm trying to do it like this:
public void rW() { byte[] bytes = { 1, 2, 3, 4 }; byte[] outputArray = new byte[4]; try (OutputStream out = new ByteArrayOutputStream(); InputStream in = new ByteArrayInputStream(out)) // но он требует массив байтов { out.write(bytes); int b; while ((b = in.read(outputArray)) != -1) { System.out.println(b); } System.out.println(Arrays.toString(outputArray)); } catch (IOException e) { e.printStackTrace(); } } It turns out that I can not directly put the output object into the input stream designer.
So how can I be here? How do I use the ByteArrayOutputStream and ByteArrayInputStream classes in the same bundle?