Example usage for java.io FileOutputStream flush

List of usage examples for java.io FileOutputStream flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:Main.java

public static void saveBitmapToCacheDir(Context context, Bitmap bitmap, String name) {
    try {/*  w ww . j  a  va2s  .  c o m*/
        File file = new File(context.getCacheDir(), name);
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream fos = context.openFileOutput(name, MODE_PRIVATE);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.ptlug.ptwifiauth.Utilities.java

public static boolean saveUserToSdCard(String user, String password) {

    try {//  w w w  .  j a  v  a 2  s  .com
        File file = new File(AppConsts.file_path, AppConsts.user_file);
        FileOutputStream fos = new FileOutputStream(file);

        fos.flush();
        fos.close();

    } catch (Exception e) {
        return false;
    }
    return true;

}

From source file:Main.java

public static void saveBitmap(Bitmap bitmap, String path) {
    try {//ww w. j  a v a 2s.  co m
        FileOutputStream out = new FileOutputStream(path);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void saveBitmap(Bitmap bm, String picName) {
    try {/*from   ww  w  .j av a2 s.  co  m*/
        if (!isFileExist("")) {
            createSDDir("");
        }
        File f = new File(SDPATH, picName);
        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

/**
 * Write the given bitmap to a file in the external storage. Requires 
 * "android.permission.WRITE_EXTERNAL_STORAGE" permission.
 *//*from   w  w  w. j  a v a 2  s  .com*/
public static void writeToFile(Bitmap bitmap, String dir, String filename)
        throws FileNotFoundException, IOException {
    File sdCard = Environment.getExternalStorageDirectory();
    File dirFile = new File(sdCard.getAbsolutePath() + "/" + dir);
    dirFile.mkdirs();
    File f = new File(dirFile, filename);
    FileOutputStream fos = new FileOutputStream(f, false);
    bitmap.compress(CompressFormat.PNG, 100 /*ignored for PNG*/, fos);
    fos.flush();
    fos.close();
}

From source file:Main.java

public static void saveBitmap(Bitmap bm, String picName) {
    try {/*www .  j  a  v  a2 s  .com*/
        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  w w  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

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.ja v a 2 s  . c  o 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

/**
 * Saves a Bitmap object to disk for analysis.
 *
 * @param bitmap The bitmap to save./*from w  w  w  .j  ava 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!");
    }
}

From source file:Main.java

public static boolean saveBitmap(Bitmap bmp, String path) {
    File file = new File(path);
    if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();/*ww  w.jav a 2 s  .com*/
    }
    if (file.exists()) {
        file.delete();
    }
    try {

        FileOutputStream out = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 80, out);
        out.flush();
        out.close();
        Log.i("saveBitmap success:", path);
        return true;
    } catch (Exception e) {
        Log.e("saveBitmap:" + path, e.toString());
    }
    return false;

}