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[] argsthrows IOException {
        byte d[] {12345678};
        //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, 25);
        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());
           }
    }

Output of the Program
 Bytes are :
3
4
5
6
7
-1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US