Java File to OutputStream outStream(String file)

Here you can find the source of outStream(String file)

Description

out Stream

License

Open Source License

Declaration

public static DataOutputStream outStream(String file) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.DataOutputStream;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static DataOutputStream outStream(String file) {
        return outStream(new File(file));
    }//from   ww  w  .j a va 2 s. co  m

    public static DataOutputStream outStream(File file) {
        DataOutputStream out = null;

        try {
            out = new DataOutputStream(new FileOutputStream(file));
        } catch (IOException err) {
            System.err.println(err.getMessage());
            err.printStackTrace();

            close(out);
            out = null;
        }

        return out;
    }

    public static void close(InputStream in) {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException err) {
            System.err.println(err.getMessage());
            err.printStackTrace();
        }
    }

    public static void close(OutputStream out) {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException err) {
            System.err.println(err.getMessage());
            err.printStackTrace();
        }
    }
}

Related

  1. openOutputStream(File file, boolean append, boolean gzip)
  2. openOutputStream(File file, int bufferSize)
  3. openOutputStream(String filePath)
  4. openOutputStream(String outputName)
  5. outStream(final File aFile)