Click here to watch in Youtube :
https://www.youtube.com/watch?v=f-ShohRXo-s&list=UUhwKlOVR041tngjerWxVccw
ByteArrayInputStreamDemo.java
Outputhttps://www.youtube.com/watch?v=f-ShohRXo-s&list=UUhwKlOVR041tngjerWxVccw
ByteArrayInputStreamDemo.java
import java.io.ByteArrayInputStream; import java.io.IOException; public class ByteArrayInputStreamDemo { public static void main(String[] args) throws IOException { ByteArrayInputStream byteArrayInputStream = null; try { byte[] buffer = new byte[5]; for (int i = 0; i < buffer.length; i++) { buffer[i] = (byte) i; } byteArrayInputStream = new ByteArrayInputStream(buffer); System.out.println("All the elements in the buffer:"); int num; /* * Read every number inside the buffer using the * read() method, which returns -1 if the end of * the buffer is reached. */ while ((num = byteArrayInputStream.read()) != -1) { System.out.print(num + " "); } } finally { if (byteArrayInputStream != null) { /* * Closing a ByteArrayInputStream has no * effect. The methods in this class can be * called after the stream has been closed * without generating an IOException. */ byteArrayInputStream.close(); } } } }
All the elements in the buffer: 0 1 2 3 4
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_ByteArrayIS_Read_ByteArray_Num_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_ByteArrayIS_Read_ByteArray_Num_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/94d38fdd49b2d33c14c088526d40f902c21a1e0d/BasicJava/JavaIODemo_ByteArrayIS_Read_ByteArray_Num_App/?at=master
See also:
No comments:
Post a Comment