Java provides PrintWriter for printing the well formatted output to the desired location. This class takes the OutputStream or Writer as the input and prints the output with the human readable format. PrintWriter defines the following constructors: PrintWriter(File file) – Creates a new PrintWriter, without automatic line flushing, with the specified file. PrintWriter(File file, String …
Java File IO
Java BufferedOutputStream Example
If you are writing the very much IO intensive application which needs to write huge amount of data to the files, then you have to do some kind of buffering to improve the performance. Here BufferedOutputStream will be helpful for writing the stream of characters into a file which internally manages a buffer for improving the …
Java FileOutputStream Example
This example discuss about the FileOutputStream. This class extends from the OutputStream and used for writing the stream of bytes into a file. This class has the following constructors for creating the instance. FileOutputStream(File file) – Creates a file output stream to write to the file represented by the specified File object. FileOutputStream(File file, boolean …
Java BufferedWriter Example
BufferedWriter is useful in writing the sequence or stream of character to a file. The is fast compared to the FileOutputStream which is writing the stream of bytes. This class directly extends from the Writer class. It has two constructors. This class has the option to set the buffer size which is internally used by …
Java StringReader Example
StringReader is extending from the Reader class. If you have string and wants to convert that to a Reader object, then StringReader is useful. It is a specialized version for using the Reader with strings. If you would like to read the Files, then choose FileReader instead of StringReader. This class has only one constructor …
Java FileWriter Example
FileWriter class useful for writing the stream of characters to a file. FileWriter extends from the OutputStreamWriter. For writing streams of bytes, implement the FileOutputStream class. This class has the different constructors to create the instance for the file object. FileWriter(File file)– Constructs a FileWriter object given a File object. FileWriter(File file, boolean append) – …
Java FileInputStream Example
FileInputStream is useful for reading the stream of bytes. If you want to read the characters, then consider using the FileReader. FileInputStream is ideal candidate for processing the image type of files which needed to be read as the binary streams. However, we can read the normal text files using the FileInputStream. This example demonstrates …
Java BufferedReader Example
In our previous example I have explained about the FileReader. FileReader is useful for reading the text content by characters. This is slow in performance when using for the huge files. BufferedReader is buffering the text for Reader’s. Buffering will speed up the IO operation. Instead of reading one character at a time using the …