DataInputStream Read1() Example
Reads some number of bytes from the contained input stream
DataInputStreamclass Read1() method example. This example shows you how to use Read1() method.This method Reads some number of bytes from the contained input stream and stores them into the buffer array b.
Here is the code:-
/**
* @Program that Reads some number of bytes from the contained input stream
* Read1.java
* Author:-RoseIndia Team
* Date:-07-jun-2008
*/
import java.io.*;
public class Read1 {
public static void main(String[] args) throws IOException {
byte[] b = {1, 2, 3, 4, 5, 6};
FileOutputStream fos = new FileOutputStream("Linux.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.write(b);
dos.flush();
dos.close();
FileInputStream fis = new FileInputStream("Linux.txt");
DataInputStream dis = new DataInputStream(fis);
int l = dis.read(b);
System.out.println("The number of bytes from the contained input stream is :"
+ l);
}
} |
Output of the Program
| The number of bytes from the contained input stream is :6 |
|