private void saveMediaFile ( final String name , final String contentType , final long size , final InputStream is ) throws AtomException { final byte [ ] buffer = new byte [ 8192 ] ; int bytesRead = 0 ; final File dirPath = new File ( getEntryMediaPath ( name ) ) ; if ( ! dirPath . getParentFile ( ) . exists ( ) ) { dirPath . getParentFile ( ) . mkdirs ( ) ; } OutputStream bos = null ; try { bos = new FileOutputStream ( dirPath . getAbsolutePath ( ) ) ; while ( ( bytesRead = is . read ( buffer , 0 , 8192 ) ) != - 1 ) { bos . write ( buffer , 0 , bytesRead ) ; } } catch ( final Exception e ) { throw new AtomException ( "ERROR uploading file" , e ) ; } finally { try { bos . flush ( ) ; bos . close ( ) ; } catch ( final Exception ignored ) { } } }
Save file to website s resource directory .