I/O streams in java

LineNumberReader Java

The character stream LineNumberReader is equivalent to LineNumberInputStream on byte streams side. Being a subclass of BufferedReader, it can make use of all the methods of BufferedReader like readLine() to read a line. getLineNumber() method of this class can be used to give line numbers. Following is the class signature…

CharArrayReader Read Character Array Java

The CharArrayReader is equivalent to ByteArrayInputStream. For ByteArrayInputStream, the source is a byte array and for CharArrayReader the source is a character array. The CharArrayReader reads characters from a character array either completely or partially starting from a offset. This classes supports mark() and reset() methods. Following is the class…

StringReader Java

StringReader of character streams is equivalent to StringBufferInputStream of byte streams. We know earlier, the StringBufferInputStream methods are deprecated in favor of StringReader. Like StringBufferInputStream, the source of data for StringReader is a string. StringReader supports mark() and reset() methods, but StringBufferInputStream does not support. Being character stream, the StringReader…

OutputStreamWriter

Bridging byte streams to character streams on writing-side The byte streams and character streams are incompatible for linking as the first one operates on 8-bit ASCII characters and the other on 16-bit Unicode characters. To link them explicitly, two classes exist in java.io package, InputStreamReader and OutputStreamWriter. Towards this functionality,…

BufferedReader and BufferedWriter File Copy

Speed up Copying Reading and copying file to file is very slow with FileReader and FileWriter as for every byte read, the control should be shifted from the execution context area of source file to the destination file and back again to read the second byte. This is what you…

Data Types Read Write Java

DataInputStream includes many methods like readByte(), readInt(), readLong(), readFloat(), readDouble() and readUTF() etc with which a byte, an integer, a long, a float, a double and a word can be read as a whole. Similarly, the DataOutputStream includes the methods like writeByte(), writeInt(), writeLong(), writeFloat(), writeDouble() and writeUTF() that can…

BufferedInputStream BufferedOutputStream

Using Buffers to Enhance the Performance Buffering of streams increases the performance to higher extents of few thousand times. For buffering, two streams exist in java.io package in byte streams category – BufferedInputStream and BufferedOutputStream. These high-level classes are subclasses of FilterInputStream and FilterOutputStream and their functionality is to increase…

PipedReader PipedWriter Example

Piping Data PipedReader PipedWriter Summary: By the end you read this tutorial "Piping Data PipedReader PipedWriter", you will understand passing data between two running processes or threads. The PipedReader and PipedWriter are character streams. Similar in byte streams are PipedInputStream and PipedOutputStream. These streams use a concept called pipe. Pipe…

SequenceInputStream Java

SequenceInputStream Java is used to copy a number of source files to one destination file. Many input streams are concatenated and converted into a single stream and copied at a stretch to the destination file. Merging of multiple files can be done easily in Java using SequenceInputStream. SequenceInputStream is a…

File class Changing File Properties

File class Changing File Properties Summary: By the end of this tutorial "File class Changing File Properties", you will come to know how to create and delete a file or create a new directory etc using Java code. After retrieving the properties of a file with File class, let us…

Filter Streams Java

In the filter streams Java category, the java.io package comes with 4 classes – FilterInputStream and FilterOutputStream on byte stream side and FilterReader and FilterWriter on character streams side. All the subclasses of these 4 classes are known as filter streams. What are filter input streams? As you can see…

Byte streams and Character streams

Byte streams Character streams File copying is done, in JDK 1.0, with byte streams. Byte streams can read or write the files containing ASCII characters that range from 0 to 255. That is, byte streams can copy the files containing English letters only but not of other languages. If the…

Byte streams vs Character streams

Byte streams vs Character streams: Character streams Advantages over Byte streams Byte streams read bytes that fall under ASCII range and character streams read Unicode characters that include characters of many international languages. Being latest, introduced with JDK 1.1, the character streams are advantageous over byte streams like the inclusion…

PrintWriter Example

PrintWriter Example Formatting Data Organizing or customizing the data, the way user wants, is known as formatting the data. PrintWriter class comes with methods to format the data and write to the output stream (not only DOS prompt) as text. This class also contains the methods of PrintStream like print()…

StreamTokenizer Tokenize Stream

Breaking a string or stream into meaningful independent words is known as tokenization. Tokenization is a common practice to tool developers. java.util package includes StringTokenizer which tokenizes a string into independent words. For StringTokenizer, the source is a string. There comes a similar tokenizer, StreamTokenize with java.io package for which…

DataInputStream DataOutputStream File Copy

DataInputStream and DataOutputStream are high-level classes as they are the subclasses of FilterInputStream and FilterOutputStream. These streams' extra functionality is that they can read or write integers, doubles and lines at a time, instead of byte by byte. This increases the performance to some extent; instead of reading and writing…

Give Line Numbers LineNumberInputStream

Give Line Numbers LineNumberInputStream Summary: By the end of this tutorial "Give Line Numbers LineNumberInputStream", you will come to know how to give line numbers using Java I/O streams. LineNumberInputStream is a subclass of FilterInputStream stream. We know each filter stream adds some extra functionality. The LineNumberInputStream does the extra…