Java IO Tutorial - Java FilterOutputStream.write(int b)








Syntax

FilterOutputStream.write(int b) has the following syntax.

public void write(int b)  throws IOException

Example

In the following code shows how to use FilterOutputStream.write(int b) method.

/*from  ww w.j a v  a2s  . c om*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.OutputStream;

public class Main {
  public static void main(String[] args) throws Exception {

    OutputStream os = new FileOutputStream("C://test.txt");
    FilterOutputStream fos = new FilterOutputStream(os);

    // writes buffer to the output stream
    fos.write(65);

    // forces byte contents to written out to the stream
    fos.flush();

    // create input streams
    FileInputStream fis = new FileInputStream("C://test.txt");

    // get byte from the file
    int i = fis.read();

    // convert integer to character
    char c = (char) i;

    System.out.print("Character read: " + c);
    fos.close();
    fis.close();
  }
}