Java ObjectOutputStream .writeShort (int val)
Syntax
ObjectOutputStream.writeShort(int val) has the following syntax.
public void writeShort(int val) throws IOException
Example
In the following code shows how to use ObjectOutputStream.writeShort(int val) method.
/* ww w. j ava 2 s . c o m*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws Exception {
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(
new FileOutputStream("file.data")));
out.writeShort(1);
out.close();
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(
new FileInputStream("file.data")));
byte[] byteArray = new byte[10];
in.read(byteArray);
System.out.println(Arrays.toString(byteArray));
in.close();
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »