Java PrintWriter Example

java-thumbnail

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 BufferedOutputStream Example

java-thumbnail

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

java-thumbnail

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 PushbackReader Example

java-thumbnail

The PushbackReader is useful when you parse data from a Reader. Sometimes you would have the requirement to read ahead a few characters to see what is coming next, before you can determine how to interprete the current character. The PushbackReader allows that facility for the programmers. This class defines two constructors. PushbackReader(Reader in) – […]

Java BufferedWriter Example

java-thumbnail

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

java-thumbnail

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

java-thumbnail

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

java-thumbnail

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 LineNumberReader Example

java-thumbnail

In my previous example I have explained about the BufferedReader¬†for reading the huge amount of data and parse it line by line. LineNumberReader is the specialized version of the BufferedReader where this class can store the line number in the file when it reads from the file. It is very useful when there is any […]

Java BufferedReader Example

java-thumbnail

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 […]