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