DataOutputStream WriteChars() Example
Writes a string to the underlying output stream as a sequence of characters.
DataOutputStreamclass WriteChars() method example. This example shows you how to use WriteChars() method.This method Writes a string to the underlying output stream as a sequence of characters.
Here is the code:-
/**
* @Program that Writes a string to the underlying output stream as a sequence
of characters.
* WriteChars.java
* Author:-RoseIndia Team
* Date:-09-jun-2008
*/
import java.io.*;
public class WriteChars {
public static void main(String[] args) throws IOException{
String s="G";
FileOutputStream fos=new FileOutputStream("g.txt");
DataOutputStream dos=new DataOutputStream(fos);
//Writes a string to the underlying output stream
dos.writeChars(s);
FileInputStream fis=new FileInputStream("g.txt");
DataInputStream dis=new DataInputStream(fis);
System.out.println("String to the underlying output stream is : "+dis.readChar());
}
} |
Output of the Program
| String to the underlying output stream is : G |
|