S. Nageswara Rao, Corporate Trainer

S. N. Rao has 20+ years hands on experience in Java and J2EE technologies. He has written 20+ books on java for students pursuing graduate and PG studies. Apart writing books, he is busy in taking corporate trainings.

markSupported() mark() reset() Java

Rereading from the Same Position The same contents of a file can be again and again read by marking the position with the methods of StringBufferInputStream, inherited from its super class InputStream. A file can be reread (reading again) from a particular location. Here, the file position is marked; execution control is taken back to …

markSupported() mark() reset() Java Read More »

Performance drawbacks File copying

Performance drawbacks File copying Summary: By the end of this tutorial "Performance drawbacks File copying", you will come to know the reasons of slow performance in file copying. Gives links to other programs to increase speed of copying. Performance drawbacks of FileInputStream and FileOutputStream Following is the for loop used in the FileToFile1.java program. while( …

Performance drawbacks File copying Read More »

StringBufferInputStream Example

StringBufferInputStream Example: As in the earlier program, where the source of reading is a byte array in case of ByteArrayInputStream, now the source is a string buffer in case of StringBufferInputStream. That is, StringBufferInputStream reads from a string buffer (or the other way, string). StringBufferInputStream class methods and constructors are deprecated (observe the compiler message …

StringBufferInputStream Example Read More »

ByteArrayOutputStream

The class ByteArrayOutputStream does just the opposite functionality of ByteArrayInputStream. The ByteArrayInputStream reads data from the array and now the ByteArrayOutputStream writes the data to the byte array. All the characters of the array can be written or a few also. In the following program, both functionalities are illustrated. import java.io.*; public class BAODemo { …

ByteArrayOutputStream Read More »

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 »