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