bytearrayinputstream

Receive byte[] using ByteArrayInputStream from a socket

人走茶凉 提交于 2019-11-29 18:28:31
问题 Here is the code but got error: bin = new ByteArrayInputStream(socket.getInputStream()); Is it possible to receive byte[] using ByteArrayInputStream from a socket? 回答1: No. You use ByteArrayInputStream when you have an array of bytes, and you want to read from the array as if it were a file. If you just want to read arrays of bytes from the socket, do this: InputStream stream = socket.getInputStream(); byte[] data = new byte[100]; int count = stream.read(data); The variable count will contain

What's the difference between InputStream and ByteArrayInputStream?

和自甴很熟 提交于 2019-11-29 06:57:43
The following code is extracted from the java web start chapter of the core java volume 1. ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream printOut = new PrintStream(out); printOut.print(panel.getText()); //panel.getText() return a String InputStream data = new ByteArrayInputStream(out.toByteArray()); FileSaveService service = (FileSaveService) ServiceManager .lookup("javax.jnlp.FileSaveService"); service.saveFileDialog(".", new String[] { "txt" }, data, "calc.txt"); There are four objects created ,the stream is redirected three times. Is there any other methods to write