ObjectOutputStream.write(byte[] buf, int off, int len) has the following syntax.
public void write(byte[] buf, int off, int len) throws IOException
In the following code shows how to use ObjectOutputStream.write(byte[] buf, int off, int len) method.
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; //from w w w.j a v a 2s . c o m public class Main { public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream( new FileOutputStream("file.data"))); out.write("java2s.com".getBytes(),1,2); 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(); } }
The code above generates the following result.