DataOutputStream WriteChar() Example
Writes a char to the underlying output stream as a 2-byte value, high byte first
DataOutputStreamclass WriteChar() method example. This example shows you how to use WriteChar() method.This method Writes a char to the underlying output stream as a 2-byte value, high byte first
Here is the code:-
/**
* @Program that Writes a char to the underlying output stream as a 2-byte
value, high byte first.
* WriteChar.java
* Author:-RoseIndia Team
* Date:-09-jun-2008
*/
import java.io.*;
public class WriteChar {
public static void main(String[] args)throws IOException {
int s=65;
FileOutputStream fos=new FileOutputStream("g.txt");
DataOutputStream dos=new DataOutputStream(fos);
//Writes a char to the underlying output stream
dos.writeChar(s);
FileInputStream fis=new FileInputStream("g.txt");
DataInputStream dis=new DataInputStream(fis);
System.out.println("Char to the underlying output stream as bytes is : "
+dis.readChar());
}
} |
Output of the Program
| Char to the underlying output stream as bytes is : A |
|