Posty

Wyświetlam posty z etykietą OutputStream

InputStreams & OutputStreams - good practices

Java.io package provides methods and classes used to handle input and output operations using data streams. We will have a look at good practices, concentrating on handling data streams using InputStream and OutputStream classes.  Usage of BufferedStreams When using unbuffered streams each write/read is handled by underlying operating system layer which then triggers disk access, network operation etc. There is a possibility to provide much better performance of Java software by minimazing calls to operating system. This is done with buffered streams. BufferedInputStream  reads data fron an in-memory area which is called buffer. Native call to OS layer is performed only when buffer is empty. This call loads big chunk of data to the buffer. After that,  BufferedInputStream    reads data from buffer (memory) rather than performing calls to OS layer,  which is much faster and has better performance.   Below is the example of how to create a...