Java Utililty Methods FileOutputStream Create

List of utility methods to do FileOutputStream Create

Description

The list of methods to do FileOutputStream Create are organized into topic(s).

Method

FileOutputStreamgetOutputStream(String filename, String dir)
get an output stream for a file
String fullFN = null;
if (null != dir) {
    fullFN = dir + "/" + filename;
    new File(dir).mkdirs();
} else {
    fullFN = filename;
return new FileOutputStream(fullFN);
...
OutputStreamWritergetOutputStream(String fname, String enc, boolean append)
Caller is responsible for write flush, close, etc.
return new OutputStreamWriter(new FileOutputStream(fname, append), enc);
DataOutputStreamgetOutputStream(String path)
Opens an output stream for the specified path.
return new DataOutputStream(new FileOutputStream(path));
OutputStreamgetOutputStream(String path)
get Output Stream
return new FileOutputStream(touch(path));
OutputStreamgetOutputStream(String root, String name, boolean overwrite, boolean verbose)
get Output Stream
if (root != null) {
    File directory = new File(root);
    if (!directory.exists()) {
        if (!directory.mkdirs()) {
            throw new IOException("Failed to create directory '" + root + "'.");
        } else if (verbose) {
            System.out.println("Created directory '" + directory.getAbsolutePath() + "'.");
File file = new File(root, name);
String absolutePath = file.getAbsolutePath();
if (file.exists()) {
    if (!overwrite) {
        throw new IOException("File '" + absolutePath + "' already exists. "
                + "Please remove it or enable the " + "overwrite option.");
    } else {
        file.delete();
        if (verbose) {
            System.out.println("Deleted file '" + absolutePath + "'.");
FileOutputStream fos = new FileOutputStream(absolutePath);
if (verbose) {
    System.out.println("Created file '" + absolutePath + "'.");
return fos;
OutputStreamgetOutputStream(String theFilePath)
get Output Stream
try {
    final OutputStream myOutputStream = new FileOutputStream(theFilePath);
    return myOutputStream;
} catch (FileNotFoundException ex) {
    ex.printStackTrace();
return null;
OutputStreamgetOutputStreamForFile(final File file)
Reads a file an returns an OutputStream from it.
return new FileOutputStream(file);
OutputStreamgetOutputStreamForFile(String filename)
get Output Stream For File
try {
    File file = new File(filename);
    if (!file.exists()) {
        file.createNewFile();
    return new FileOutputStream(file);
} catch (IOException e) {
    throw new IllegalStateException(e);
...
voidwriteFile(File outFile, ZipInputStream zipInputStream, ZipEntry entry)
Write data.
try {
    if (entry.isDirectory()) {
        return;
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outFile));
    int data = 0;
    try {
        while ((data = zipInputStream.read()) != -1) {
...
booleanwriteFile(FileOutputStream fileoutputstream, byte abyte0[], int i)
write File
try {
    fileoutputstream.write(abyte0, 0, i);
    return true;
} catch (IOException ex) {
    System.err.println("File cannot be written.");
    return false;