public static boolean esPDF ( File file ) { boolean ret = false ; FileReader reader = null ; try { reader = new FileReader ( file ) ; char [ ] buffer = new char [ 4 ] ; reader . read ( buffer , 0 , 4 ) ; ret = ( "%PDF" . equals ( String . valueOf ( buffer ) ) ) ; } catch ( FileNotFoundException e ) { log . error ( "Error: no se encuentra el fichero " + file . getAbsolutePath ( ) ) ; } catch ( IOException e ) { log . error ( "Error leyendo el fichero " + file . getAbsolutePath ( ) ) ; } finally { try { reader . close ( ) ; } catch ( IOException e ) { log . error ( "Error cerrando el fichero " + file . getAbsolutePath ( ) ) ; } } return ret ; }
Nos dice si un fichero es un PDF