DataInputStream ReadShort() Example
returns the next two bytes of this input stream, interpreted as a signed 16-bit number
DataInputStreamclass ReadShort() method example. This example shows you how to use ReadShort() method.This method returns the next two bytes of this input stream, interpreted as a signed 16-bit number
Here is the code:-
/**
* @Program that returns the next two bytes of this input stream, interpreted as a
signed 16-bit number.
* ReadShort.java
* Author:-RoseIndia Team
* Date:-07-jun-2008
*/
import java.io.*;
public class ReadShort {
public static void main(String[] args)throws IOException {
short lL = 23;
FileOutputStream fos = new FileOutputStream("Linux.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeShort(lL);
dos.flush();
dos.close();
FileInputStream fis = new FileInputStream("Linux.txt");
DataInputStream dis = new DataInputStream(fis);
//returns the next two bytes of this input stream, interpreted
//as a short.
short l = dis.readShort();
System.out.println("The next eight bytes of this input stream is :" + l);
}
} |
Output of the Program
| The next eight bytes of this input stream is :23 |
|