Java FileOutputStream Create getOutputStream(File file)

Here you can find the source of getOutputStream(File file)

Description

get Output Stream

License

Open Source License

Declaration

public static OutputStream getOutputStream(File file) 

Method Source Code

//package com.java2s;
/* //from w  ww .  j av  a  2 s.co  m
    
 Created on Mar 4, 2005
    
 The Bungee View applet lets you search, browse, and data-mine an image collection.  
 Copyright (C) 2006  Mark Derthick
    
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.  See gpl.html.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
 You may also contact the author at 
 mad@cs.cmu.edu, 
 or at
 Mark Derthick
 Carnegie-Mellon University
 Human-Computer Interaction Institute
 Pittsburgh, PA 15213
    
 */

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.OutputStream;

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static OutputStream getOutputStream(File file) {
        assert file != null;
        OutputStream out = null;
        try {
            out = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            System.err.println("Can't find file " + file);
            e.printStackTrace();
        }
        return out;
    }

    public static String printStackTrace() {
        (new RuntimeException("Relax.  There's no error, we're just printing the stack trace")).printStackTrace();
        return null;
    }

    public static String printStackTrace(Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }
}

Related

  1. getOutputStream(File file)
  2. getOutputStream(File file, String filePath)
  3. getOutputStream(final File file)
  4. getOutputStream(final File file)
  5. getOutputStream(final Object obj, final boolean append)