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 String saveToInternalSorage(Bitmap bitmapImage, String filename, Context context) {
    File mypath = new File(getImagesDirectory(context), filename);
    FileOutputStream fos = null;
    try {//from   w  ww.  j av  a  2  s .c o m
        fos = new FileOutputStream(mypath);
        bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mypath.getAbsolutePath();
}

From source file:Main.java

public static void saveBitmap(Bitmap bm, String picName) {
    try {/*from  w ww .j  av  a  2 s.c  o m*/
        if (!isFileExist("")) {
            File tempf = createSDDir("");
        }
        File f = new File(SDPATH, picName + ".JPEG");
        if (f.exists()) {
            f.delete();
        }
        FileOutputStream out = new FileOutputStream(f);
        bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * @param fileName /*from  ww w. j  a va 2s . c om*/
 * @param message
 */
public static void writeFileSdcard(String fileName, String message) {

    try {

        FileOutputStream fout = new FileOutputStream(fileName);
        byte[] bytes = message.getBytes();
        fout.write(bytes);
        fout.flush();
        fout.close();
    }

    catch (Exception e) {

        e.printStackTrace();

    }

}

From source file:Main.java

/**
 * Copy a file from one place to another
 *//*w  w w  . j a v a2  s . c  o  m*/
private static void copyFile(File in, File out) throws Exception {
    FileInputStream fis = new FileInputStream(in);
    FileOutputStream fos = new FileOutputStream(out);
    try {
        copyStream(fis, fos);
    } finally {
        fis.close();
        fos.close();
    }
}

From source file:Main.java

private static String saveCroppedImage(Bitmap bmp) {
    File file = new File("/sdcard/myFolder");
    UUID uuid = UUID.randomUUID();
    String uid = uuid.toString();
    if (!file.exists())
        file.mkdir();//from w  w  w .j  a v  a  2s  . co  m
    String name = "/sdcard/" + uid + ".jpg";
    file = new File(name.trim());
    String fileName = file.getName();
    String mName = fileName.substring(0, fileName.lastIndexOf("."));
    String sName = fileName.substring(fileName.lastIndexOf("."));

    // /sdcard/myFolder/temp_cropped.jpg
    String newFilePath = "/sdcard/myFolder" + "/" + mName + "_cropped" + sName;
    file = new File(newFilePath);
    try {
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 50, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return newFilePath;
}

From source file:Main.java

/**
 * Copy a file from one place to another
 * @throws Exception/*from  w w w  .j  ava 2  s .  co  m*/
 */
public static void copyFile(File in, File out) throws Exception {
    FileInputStream fis = new FileInputStream(in);
    FileOutputStream fos = new FileOutputStream(out);
    try {
        copyStream(fis, fos);
    } finally {
        fis.close();
        fos.close();
    }
}

From source file:Main.java

/**
 * Writes the given {@link Document} to a {@link File}.
 *
 * @param doc The {@link Document} to write.
 * @param file The {@link File} to write to.
 * @see #encodeDocument(Document,boolean)
 * @see #writeDocumentTo(Document,OutputStream)
 *///from  ww  w . j  a  v  a 2  s.c om
public static void writeDocumentTo(Document doc, File file) throws IOException {
    final FileOutputStream fos = new FileOutputStream(file);
    try {
        writeDocumentTo(doc, fos);
    } finally {
        fos.close();
    }
}

From source file:foss.filemanager.core.Utils.java

public static File arrayByteToFile(byte[] fileBArray) throws FileNotFoundException, IOException {
    DateFormat df = new SimpleDateFormat("ddMMyyyy-hhmmss-S");
    String name = df.format(new Date());
    String tmp = System.getProperty("java.io.tmpdir");
    File file = new File(tmp, name);
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(fileBArray);/*from   www.j  a  v  a2  s . c o  m*/
    fos.close();
    return file;
}

From source file:Main.java

public static void saveThumb(Context context, String thumbName, Bitmap image) {
    if (thumbName == null || thumbName.length() <= 0)
        return;/*from  w  w  w .ja v a  2  s .c  om*/

    File pictureFile = getOutputMediaFile(context, thumbName);
    File dir = new File(context.getCacheDir() + "/thumbnails");
    if (dir.exists())//too many caches
    {
        File files[] = dir.listFiles();
        if (files.length > CACHE_LIMIT)
            files[0].deleteOnExit();
    }
    if (pictureFile == null) {
        Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage());
        return;
    }
    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        image.compress(Bitmap.CompressFormat.PNG, 90, fos);
        fos.close();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

From source file:Main.java

/**
 * Saves a Bitmap object to disk for analysis.
 *
 * @param bitmap The bitmap to save.//from   ww  w .j a v  a  2  s. c  o m
 */
public static void saveBitmap(final Bitmap bitmap) {
    final String root = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "tensorflow";
    //LOGGER.i("Saving %dx%d bitmap to %s.", bitmap.getWidth(), bitmap.getHeight(), root);
    final File myDir = new File(root);

    if (!myDir.mkdirs()) {
        //LOGGER.i("Make dir failed");
    }

    final String fname = "preview.png";
    final File file = new File(myDir, fname);
    if (file.exists()) {
        file.delete();
    }
    try {
        final FileOutputStream out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 99, out);
        out.flush();
        out.close();
    } catch (final Exception e) {
        //LOGGER.e(e, "Exception!");
    }
}