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[] argv) throws Exception {
    FileOutputStream fileOut = new FileOutputStream("data.txt");
    BufferedOutputStream buffer = new BufferedOutputStream(fileOut);
    DataOutputStream dataOut = new DataOutputStream(buffer);
    dataOut.writeUTF("Hello!");
    dataOut.writeInt(4);/*from w w  w .ja  va  2  s .c o m*/
    dataOut.writeDouble(100.0);
    dataOut.close();
    buffer.close();
    fileOut.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    System.setOut(new LogStream(System.out, new PrintStream(new FileOutputStream("out.log"))));
    System.setErr(new LogStream(System.err, new PrintStream(new FileOutputStream("err.log"))));

    System.out.println("output");
    System.err.println("error");
}

From source file:MainClass.java

public static void main(String args[]) {

    try {/*from   ww w . ja  v  a  2  s .c o  m*/

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

        BufferedOutputStream bos = new BufferedOutputStream(fos);

        for (int i = 0; i < 12; i++) {
            bos.write(i);
        }

        bos.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("output.dat"))));

}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*  www. j  a  v  a 2 s  .c  o  m*/

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

        DataOutputStream dos = new DataOutputStream(fos);

        dos.writeBoolean(false);
        dos.writeByte(Byte.MAX_VALUE);
        dos.writeChar('A');
        dos.writeDouble(Double.MAX_VALUE);
        dos.writeFloat(Float.MAX_VALUE);
        dos.writeInt(Integer.MAX_VALUE);
        dos.writeLong(Long.MAX_VALUE);
        dos.writeShort(Short.MAX_VALUE);

        fos.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    byte buf[] = new byte[] { 66, 67, 68, 69 };
    OutputStream f0 = new FileOutputStream("file1.txt");
    OutputStream f1 = new FileOutputStream("file2.txt");
    OutputStream f2 = new FileOutputStream("file3.txt");
    for (int i = 0; i < buf.length; i++) {
        f0.write(buf[i]);//w  ww  .ja v  a  2s  .  c om
    }
    f0.close();
    f1.write(buf);
    f1.close();
    f2.write(buf, buf.length / 4, buf.length / 2);
    f2.close();
}

From source file:Main.java

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

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

    // releases any system resources associated with the stream
    fos.close();//w  ww .jav  a2s.co m

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

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream("outfile.gzip"));
    FileInputStream in = new FileInputStream("infilename");

    byte[] buf = new byte[1024];
    int len;/*  w  w  w . j  a va  2 s .  c  om*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    out.finish();
    out.close();
}

From source file:Main.java

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

    Formatter formatter = new Formatter(new FileOutputStream("generated/format.txt"));

    // format a new string
    String name = "from java2s.com";
    formatter.format("Hello %s !", name);

    // print the formatted string
    System.out.println(formatter);

    // flush the formatter. Here it does nothing.
    formatter.flush();//from ww  w.  j  a  v  a  2  s.  c om
    System.out.println("Formatter Flushed.");
}

From source file:Main.java

public static void main(String[] arguments) {
    int[] data = { 137, 89, 82, 181, 50, 220, 103, 20, 0, 59 };
    try {//from w  w w.  ja  v a2 s. c  o  m
        FileOutputStream file = new FileOutputStream("pic.dat");
        for (int i = 0; i < data.length; i++)
            file.write(data[i]);
        file.close();
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}