In this Java IO Tutorial, we will learn about ByteArrayInputStream. Here, we will create the stream out of byte[] and read the contents.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
private void btnReadDataActionPerformed(java.awt.event.ActionEvent evt) { //Sample 003.1: Get Text From text Area String strData = TaInput.getText(); byte[] byteData = strData.getBytes(); //Sample 003.2: Create Byte Array Input Stream ByteArrayInputStream byteInStream = new ByteArrayInputStream(byteData); //Sample 003.3: Now we read the Byte Array & add to Output int chardata; String text = ""; while((chardata=byteInStream.read()) != -1) { //Sample 003.4: Let us Look at actual stream //text = text + chardata; //TaOutput.append(text); //Sample 003.5: Let us Look at actual stream text = text + (char)chardata; TaOutput.setText(text); } } |
Categories: Java-Tube