public static long getFileLength ( final File file ) throws FileNotFoundException { try { return AccessController . doPrivileged ( new PrivilegedExceptionAction < Long > ( ) { @ Override public Long run ( ) throws FileNotFoundException { return file . length ( ) ; } } ) ; } catch ( PrivilegedActionException e ) { // Creating a FileOutputStream can only return a FileNotFoundException throw ( FileNotFoundException ) e . getCause ( ) ; } }
Java 2 security APIs for file length