Posts

Showing posts with the label Streams

Program to create text file, write some data and read the same using single character method without using string functions

 In this tutorial, you'll learn how to create TEXT file, write some data to file and read the data from text file. Before going to start you should aware of the following concepts: Java File IO FileWriter class FileReader class

Program to split the words in sentence of string without using split in Java

 In this program, you'll learn how to split the words in sentence of string without using split() function. Hello Guys, if you know about split( ) method of String class, it can be used to split the sentence into words. Here in this program we will split the using without using this split() method. So let us start.

Program to write data into file using Character Stream

Character Streams are specially designed to read and write data from and to the Streams of Characters. We require this specialized Stream because of different file encoding systems. We should not use Byte Streams for Reading and Writing character files. In Character Streams all the classes are the descendents of 2 abstract classes: Reader for reading operation. Writer for writing operation. The 2 most important methods in all the classes that are used for I/O operations are: public int read( ) throws IOException : It reads a character from stream. public int write(int i) throws IOException : It writes the Character into the Stream. Data into 16 lower bits are converted into characters and higher 16 bits are ignored..

Program to read the contents of file using Character Stream

Character Streams  are specially designed to read and write data from and to the Streams of Characters. We require this specialized Stream because of different file encoding systems. We should not use  Byte Streams  for Reading and Writing character files. In Character Streams all the classes are the descendents of 2 abstract classes: Reader  for reading operation. Writer  for writing operation.

Program for reading bytes from file using FileInputStream (Byte Stream)

In Java,  FileInputStream  is a bytes stream class that’s used to read bytes from file. The following program will use FileInputStream to read a file named 'test.txt' and display its content to console. The FileInputStream class is present in  java.io  package. To read the contents from a file you have to follow below stpes: Create an object of  FileInputStream  by passing filename in constructor call. This statement throws  FileNotFoundException  so you have to surround this statement with try-catch block. To read bytes from stream use,  int read( )  method of FileInputStream class. This method reads a byte from stream. This method returns next byte of data from file or -1 if the end of the file is reached. Read method throws IOException in case of any IO errors. To close the FileInputStream, use  void close( )  method of FileInputStream class. This also throws IOException. The following program will the read the co...