public static File getWebFile ( final String path ) { final ServletContext servletContext = AbstractServletListener . getServletContext ( ) ; File ret ; try { final URL resource = servletContext . getResource ( path ) ; if ( null == resource ) { return null ; } ret = FileUtils . toFile ( resource ) ; if ( null == ret ) { final File tempdir = ( File ) servletContext . getAttribute ( "javax.servlet.context.tempdir" ) ; ret = new File ( tempdir . getPath ( ) + path ) ; FileUtils . copyURLToFile ( resource , ret ) ; ret . deleteOnExit ( ) ; } return ret ; } catch ( final Exception e ) { LOGGER . log ( Level . ERROR , "Reads file [path=" + path + "] failed" , e ) ; return null ; } }
Gets a file in web application with the specified path .