Example usage for java.io FileOutputStream close

List of usage examples for java.io FileOutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this file output stream and releases any system resources associated with this stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("a.gz");
    GZIPInputStream gzin = new GZIPInputStream(fin);
    FileOutputStream fout = new FileOutputStream("a.dat");
    for (int c = gzin.read(); c != -1; c = gzin.read()) {
        fout.write(c);//from   w w w.j  a v  a 2s . c  o  m
    }
    fout.close();
}

From source file:Main.java

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

    FileInputStream fin = new FileInputStream("a.dat");
    InflaterInputStream iis = new InflaterInputStream(fin);
    FileOutputStream fout = new FileOutputStream("b.dat");
    for (int c = iis.read(); c != -1; c = iis.read()) {
        fout.write(c);//  ww w  .j a  v a2 s.c om
    }
    fout.close();

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String password = "password";

    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
    keyPairGenerator.initialize(1024);/*from   www. j  ava  2s .  co m*/
    KeyPair keyPair = keyPairGenerator.genKeyPair();
    String publicKeyFilename = "public";

    byte[] publicKeyBytes = keyPair.getPublic().getEncoded();

    FileOutputStream fos = new FileOutputStream(publicKeyFilename);
    fos.write(publicKeyBytes);
    fos.close();

    String privateKeyFilename = "privateKeyFilename";

    byte[] privateKeyBytes = keyPair.getPrivate().getEncoded();

    byte[] encryptedPrivateKeyBytes = passwordEncrypt(password.toCharArray(), privateKeyBytes);

    fos = new FileOutputStream(privateKeyFilename);
    fos.write(encryptedPrivateKeyBytes);
    fos.close();
}

From source file:CopyBytes.java

public static void main(String[] args) throws IOException {
    File inputFile = new File("input.txt");
    File outputFile = new File("output.txt");

    FileInputStream in = new FileInputStream(inputFile);
    FileOutputStream out = new FileOutputStream(outputFile);
    int c;/*from  ww  w  .j  ava  2 s .  com*/

    while ((c = in.read()) != -1)
        out.write(c);

    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String strFilePath = "C://demo.txt";
    FileOutputStream fos = new FileOutputStream(strFilePath);
    String strContent = "Write File using Java FileOutputStream example !";
    fos.write(strContent.getBytes());/*from w  w  w.  j av  a  2  s. c  o m*/
    fos.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    int howMany = 20;
    // To avoid resizing the buffer, calculate the size of the
    // byte array in advance.
    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
        dout.writeInt(i);/*from w  w  w  .j  a  va 2s . c o  m*/
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
        bout.writeTo(fout);
        fout.flush();
    } finally {
        fout.close();
    }
}

From source file:Hex.java

public static void main(String[] args) {
    if (args.length != 3) {
        System.out.println("Usage: HexStrToBin enc/dec <infileName> <outfilename>");
        System.exit(1);//from  ww w  .ja v a  2  s. c o m
    }
    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        InputStream in = new FileInputStream(args[1]);
        int len = 0;
        byte buf[] = new byte[1024];
        while ((len = in.read(buf)) > 0)
            os.write(buf, 0, len);
        in.close();
        os.close();

        byte[] data = null;
        if (args[0].equals("dec"))
            data = decode(os.toString());
        else {
            String strData = encode(os.toByteArray());
            data = strData.getBytes();
        }

        FileOutputStream fos = new FileOutputStream(args[2]);
        fos.write(data);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

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

    int howMany = 20;

    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
        dout.writeInt(i);/*from w w  w  . j  a va2s  .c o m*/
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
        bout.writeTo(fout);
        fout.flush();
    } finally {
        fout.close();
    }
}

From source file:Base64Decode.java

/**
  * A test method of questionable utility.
  *///from  w w w  .  ja  v a 2  s. c o  m
public static void main(String args[]) {
    try {
        FileOutputStream fos = new FileOutputStream("out.dat");

        fos.write(decode(System.in));
        fos.close();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
}

From source file:MainClass.java

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

    int howMany = 20;

    // To avoid resizing the buffer, calculate the size of the
    // byte array in advance.
    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
        dout.writeInt(i);/*from  ww w. j a v  a2 s . c om*/
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
        bout.writeTo(fout);
        fout.flush();
    } finally {
        fout.close();
    }
}