@Test public void testWritePrivateFile() throws Exception { final byte[] data = new byte[] { 0x1, 0x2, 0x3, 0x4, 0x8 }; final String fileName = "testFileForWrite"; final Context context = RuntimeEnvironment.application; context.deleteFile(fileName); FileUtils.writeOrDeletePrivateFile(context, fileName, data); final InputStream is = context.openFileInput(fileName); final byte[] read = ByteStreams.toByteArray(is); assertArrayEquals(data, read); }
public static boolean writeOrDeletePrivateFile(@NonNull final Context context, @NonNull final String fileName, @Nullable final byte[] data) { context.deleteFile(fileName); if (data == null) { return true; } else { OutputStream os = null; try { os = context.openFileOutput(fileName, Context.MODE_PRIVATE); os.write(data); os.close(); return true; } catch (IOException e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.w(TAG, e); } } } } return false; }
FileUtils { public static boolean writeOrDeletePrivateFile(@NonNull final Context context, @NonNull final String fileName, @Nullable final byte[] data) { context.deleteFile(fileName); if (data == null) { return true; } else { OutputStream os = null; try { os = context.openFileOutput(fileName, Context.MODE_PRIVATE); os.write(data); os.close(); return true; } catch (IOException e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.w(TAG, e); } } } } return false; } }
FileUtils { public static boolean writeOrDeletePrivateFile(@NonNull final Context context, @NonNull final String fileName, @Nullable final byte[] data) { context.deleteFile(fileName); if (data == null) { return true; } else { OutputStream os = null; try { os = context.openFileOutput(fileName, Context.MODE_PRIVATE); os.write(data); os.close(); return true; } catch (IOException e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.w(TAG, e); } } } } return false; } private  FileUtils(); }
FileUtils { public static boolean writeOrDeletePrivateFile(@NonNull final Context context, @NonNull final String fileName, @Nullable final byte[] data) { context.deleteFile(fileName); if (data == null) { return true; } else { OutputStream os = null; try { os = context.openFileOutput(fileName, Context.MODE_PRIVATE); os.write(data); os.close(); return true; } catch (IOException e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.w(TAG, e); } } } } return false; } private  FileUtils(); @NonNull static byte[] readPrivateFile(@NonNull final Context context,
            @NonNull final String fileName); static boolean writeOrDeletePrivateFile(@NonNull final Context context,
            @NonNull final String fileName,
            @Nullable final byte[] data); }
FileUtils { public static boolean writeOrDeletePrivateFile(@NonNull final Context context, @NonNull final String fileName, @Nullable final byte[] data) { context.deleteFile(fileName); if (data == null) { return true; } else { OutputStream os = null; try { os = context.openFileOutput(fileName, Context.MODE_PRIVATE); os.write(data); os.close(); return true; } catch (IOException e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.w(TAG, e); } } } } return false; } private  FileUtils(); @NonNull static byte[] readPrivateFile(@NonNull final Context context,
            @NonNull final String fileName); static boolean writeOrDeletePrivateFile(@NonNull final Context context,
            @NonNull final String fileName,
            @Nullable final byte[] data);  }