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