Java IO Tutorial - Java FileOutputStream (FileDescriptor fdObj) Constructor








Syntax

FileOutputStream(FileDescriptor fdObj) constructor from FileOutputStream has the following syntax.

public FileOutputStream(FileDescriptor fdObj)

Example

In the following code shows how to use FileOutputStream.FileOutputStream(FileDescriptor fdObj) constructor.

//from   w w  w.  j ava 2 s  . c o  m

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

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

    byte b = 66;
    int i = 0;
    FileOutputStream fos = new FileOutputStream(FileDescriptor.out);

    fos.write(b);

    fos.flush();

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

    // read till the end of the file
    while ((i = fis.read()) != -1) {
      // convert integer to character
      char c = (char) i;

      System.out.print(c);
    }
    fos.close();
    fis.close();
  }
}