src/main/java/org/jboss/util/file/Files.java
/**
    * Copy a remote/local URL to a local file
    * 
    * @param src the remote or local URL
    * @param dest the local file
    * @throws IOException upon error
    */
Copy a remote/local URL to a local file

@param src the remote or local URL
@param dest the local file
@throws IOException upon error
Copy a remote / local URL to a local file @param src the remote or local URL @param dest the local file @throws IOException upon error
public static void copy(URL src, File dest) throws IOException
   {
      log.debug("Copying " + src + " -> " + dest);
      File dir = dest.getParentFile();
      if (!dir.exists())
      {
         if (!dir.mkdirs())
         {
            throw new IOException("mkdirs failed for: " + dir.getAbsolutePath());
         }
      }
      if (dest.exists())
      {
         if (!Files.delete(dest))
         {
            throw new IOException("delete of previous content failed for: " + dest.getAbsolutePath());
         }
      }
      InputStream in = new BufferedInputStream(src.openStream());
      OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
      Streams.copy(in, out);
      out.flush();
      out.close();
      in.close();
   }
public static void copy ( URL src , File dest ) throws IOException { log . debug ( "Copying " + src + " -> " + dest ) ; File dir = dest . getParentFile ( ) ; if ( ! dir . exists ( ) ) { if ( ! dir . mkdirs ( ) ) { throw new IOException ( "mkdirs failed for: " + dir . getAbsolutePath ( ) ) ; } } if ( dest . exists ( ) ) { if ( ! Files . delete ( dest ) ) { throw new IOException ( "delete of previous content failed for: " + dest . getAbsolutePath ( ) ) ; } } InputStream in = new BufferedInputStream ( src . openStream ( ) ) ; OutputStream out = new BufferedOutputStream ( new FileOutputStream ( dest ) ) ; Streams . copy ( in , out ) ; out . flush ( ) ; out . close ( ) ; in . close ( ) ; }
Copy a remote/local URL to a local file
Copy a remote / local URL to a local file
// Validate that the dest parent directory structure exists // Remove any existing dest content // Treat local and remote URLs the same // prepare streams, do the copy and flush