PrintStream Write() Example
Writes len bytes from the specified byte array starting at offset off to this stream.
PrintStreamclass Write() method example. This example shows you how to use Write() method.This method Writes len bytes from the specified byte array starting at offset off to this stream.
Here is the code:-
/**
* @Program that Writes len bytes from the specified byte array starting at
* offset off to this stream
* Write.java
* Author:-RoseIndia Team
* Date:-10-Jun-2008
*/
import java.io.*;
public class Write {
public static void main(String[] args) throws IOException {
byte d[] = {1, 2, 3, 4, 5, 6, 7, 8};
//Creating FileOutputStream object
FileOutputStream out = new FileOutputStream("text.txt");
FileInputStream fin = new FileInputStream("text.txt");
//Creating PrintStream object
PrintStream ps = new PrintStream(out);
//Writes len bytes from the specified byte array
ps.write(d, 2, 5);
System.out.println("Bytes are : ");
System.out.println(fin.read());
System.out.println(fin.read());
System.out.println(fin.read());
System.out.println(fin.read());
System.out.println(fin.read());
System.out.println(fin.read());
}
} |
|