Example usage for java.io FileOutputStream FileOutputStream

List of usage examples for java.io FileOutputStream FileOutputStream

Introduction

In this page you can find the example usage for java.io FileOutputStream FileOutputStream.

Prototype

public FileOutputStream(FileDescriptor fdObj) 

Source Link

Document

Creates a file output stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/demo.txt");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/demo.txt");

    byte b = 01;/*from   w  w w.j a va 2 s . c  om*/
    fos.write(b);
    fos.close();
}

From source file:Main.java

public static void main(String[] args) {

    try {/*  w  w  w  .  j  a  v  a  2s .  co  m*/
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);

        // flush the stream
        writer.flush();

        // read what we write
        System.out.println((char) in.read());

        // close the stream
        writer.close();
        os.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:FileOutputStreamDemo.java

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

    FileOutputStream fos = new FileOutputStream(args[0]);

    // Write 12 bytes to the file
    for (int i = 0; i < 12; i++) {
        fos.write(i);/*w w w. java2s.c  om*/
    }

    // Close file output stream
    fos.close();
}

From source file:Main.java

public static void main(String[] args) {
    try {/*from w  ww  . j  av a2 s  .  c  o m*/
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);
        writer.write(71);
        writer.write(72);

        // flush the stream
        writer.flush();

        // read what we write
        for (int i = 0; i < 3; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {//from ww  w  .ja  va2 s .  c  o m
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);

        // flush the stream
        writer.flush();

        // get and print the encoding for this stream
        System.out.println(writer.getEncoding());

        // read what we write
        System.out.println((char) in.read());
        writer.close();
        os.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.setOut(new PrintStream(new FileOutputStream("system_out.txt")));
    System.out.println("sent to the file system_out.txt");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileOutputStream os = new FileOutputStream("outfilename");
    FileDescriptor fd = os.getFD();
    os.write(1);/*ww w .j a v  a 2s  .  co  m*/
    os.flush();
    fd.sync();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileOutputStream os = new FileOutputStream("outfilename");
    FileDescriptor fd = os.getFD();
    os.write(1);/*from   w w w  . jav a2s  . c o  m*/
    os.flush();
    fd.valid();
}

From source file:Main.java

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

    FileOutputStream f = new FileOutputStream("file.txt");

    System.setErr(new PrintStream(f));

    System.err.println("This will get redirected to file from java2s.com");
}