Code example for FileOutputStream

Methods: close, write

0
        public void onPictureTaken(byte[] data, Camera camera) { 
            FileOutputStream fos = null; 
 
            try { 
                Log.v(TAG, "JPEG picture taken"); 
                fos = new FileOutputStream(String.format("%s/%s/%s-%d.jpg", 
                        Environment.getExternalStorageDirectory(), CAMERA_STRESS_IMAGES_DIRECTORY, 
                        CAMERA_STRESS_IMAGES_PREFIX, System.currentTimeMillis())); 
                fos.write(data); 
            } catch (FileNotFoundException e) { 
                Log.e(TAG, "File not found: " + e.toString()); 
            } catch (IOException e) { 
                Log.e(TAG, "Error accessing file: " + e.toString()); 
            } finally { 
                try { 
                    if (fos != null) { 
                        fos.close(); 
                    } 
                } catch (IOException e) { 
                    Log.e(TAG, "Error closing file: " + e.toString()); 
                } 
            }