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 {
    short b = 32767;

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeShort(b);//  www .  ja  v  a  2s. co m
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print the short
    System.out.println(ois.readUnsignedShort());
    ois.close();
}

From source file:FileDeflater.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("a.dat");
    FileOutputStream fout = new FileOutputStream("b.dat");
    DeflaterOutputStream dos = new DeflaterOutputStream(fout);
    for (int c = fin.read(); c != -1; c = fin.read()) {
        dos.write(c);// ww  w .j  a v  a  2  s  .com
    }
    dos.close();
    fin.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int sChunk = 8192;

    String zipname = "a.gz";
    FileOutputStream out = new FileOutputStream(zipname);
    GZIPOutputStream zipout = new GZIPOutputStream(out);
    byte[] buffer = new byte[sChunk];

    FileInputStream in = new FileInputStream(args[0]);
    int length;/*from   w  w  w . j  a  v a 2 s  . com*/
    while ((length = in.read(buffer, 0, sChunk)) != -1)
        zipout.write(buffer, 0, length);
    in.close();
    zipout.close();

}

From source file:Main.java

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

    byte b = 66;//www .j  a v a  2  s . c o m
    int i = 0;
    FileOutputStream fos = new FileOutputStream(new File("C://test1.txt"));

    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();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileChannel srcChannel = new FileInputStream("srcFilename").getChannel();
    FileChannel dstChannel = new FileOutputStream("dstFilename").getChannel();

    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
    srcChannel.close();/*from  w ww  . ja  va2  s.  c o m*/
    dstChannel.close();
}

From source file:List.java

public static void main(String args[]) throws Exception {
    Properties p = System.getProperties();
    p.list(System.out);//from  w w  w  . j  a v  a  2 s . c o m
    FileOutputStream fos = new FileOutputStream("sys.out");
    p.store(fos, null);
    fos.close();
    Map map = new TreeMap(p);
    System.out.println(map);
}

From source file:Main.java

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

    String inFilename = "infilename";
    FileInputStream in = new FileInputStream(inFilename);

    byte[] buf = new byte[1024];
    int len;/*from  www.ja va 2  s . c o m*/
    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 Exception {

    float f = 1.23456f;

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    oout.writeFloat(f);//ww  w.  jav  a2 s  .  c o m
    oout.writeFloat(1234.56789f);
    oout.flush();
    oout.close();

    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    System.out.println(ois.readFloat());

    System.out.println(ois.readFloat());
    ois.close();
}

From source file:Main.java

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

    byte[] b = { 65, 66, 67, 68, 69 };
    int i = 0;/*  w ww.ja  v  a2  s  . co  m*/

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

    // writes byte to the output stream
    fos.write(b, 2, 3);

    // flushes the content to the underlying stream
    fos.flush();

    // create new file input stream
    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);
    }
}

From source file:Main.java

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

    short s = 56;

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeShort(s);/*w  w w  .  j a va 2  s. c o m*/
    oout.writeShort(new Short("1"));
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print a short
    System.out.println(ois.readShort());

    // read and print a short
    System.out.println(ois.readShort());
    ois.close();
}