DataInputStream ReadChar() Example

returns the next two bytes of this input stream, interpreted as a char.


DataInputStreamclass ReadChar() method example. This example shows you how to use ReadChar() method.This method returns the next two bytes of this input stream, interpreted as a char.

Here is the code:-
/**
 * @Program that returns the next two bytes of this input stream, interpreted 
    as a char. 
 * ReadChar.java 
 * Author:-RoseIndia Team
 * Date:-07-jun-2008
 */
import java.io.*;
public class ReadChar {
public static void main(String[] argsthrows IOException{
        char cC='G';
        FileOutputStream fos = new FileOutputStream("Linux.txt");
        DataOutputStream dos = new DataOutputStream(fos);
        dos.writeChar(cC);
        dos.flush();
        dos.close();
        FileInputStream fis = new FileInputStream("Linux.txt");
        DataInputStream dis = new DataInputStream(fis);
        //returns the next two bytes of this input stream, interpreted 
            //as a char. 
        char c=dis.readChar();
        System.out.println("The next two bytes of this input stream is :"+c);
    }

}

Output of the Program
The next two bytes of this input stream is :G

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US