public String fileToString ( File f ) throws MelcoePDPException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; byte [ ] bytes = new byte [ 1024 ] ; try { FileInputStream fis = new FileInputStream ( f ) ; int count = fis . read ( bytes ) ; while ( count > - 1 ) { out . write ( bytes , 0 , count ) ; count = fis . read ( bytes ) ; } fis . close ( ) ; } catch ( IOException e ) { throw new MelcoePDPException ( "Error reading file: " + f . getName ( ) , e ) ; } return out . toString ( ) ; }
Read file and return contents as a string