I/O streams in java

i/o streams in java,Input/Output Streams in Core Java,Java I/O Tutorial

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 of LineNumberReader Java: public class …

LineNumberReader Java Read More »

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 signature public class CharArrayReader extends …

CharArrayReader Read Character Array Java Read More »

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 operates on Unicode data. Following …

StringReader Java Read More »

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, we have seen earlier InputStreamReader …

OutputStreamWriter Read More »

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 have done in Semantics of …

BufferedReader and BufferedWriter File Copy Read More »

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 write a byte, an integer, …

Data Types Read Write Java Read More »

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 the performance with buffer. These …

BufferedInputStream BufferedOutputStream Read More »

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 is used to pass data …

PipedReader PipedWriter Example Read More »

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 good example to show that …

SequenceInputStream Java Read More »

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 of newLine() method (that is …

Byte streams vs Character streams Read More »

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 source is a stream. Here, …

StreamTokenizer Tokenize Stream Read More »

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 byte by byte with FileInputStream …

DataInputStream DataOutputStream File Copy Read More »

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 work of adding line numbers …

Give Line Numbers LineNumberInputStream Read More »