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[] argsthrows 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

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

HOME | COPYRIGHT | CONTACT US